Attachment 'circledot_factorials.py'
Download 1 import sys
2
3 n = int(sys.argv[1])
4 k = int(sys.argv[2])
5
6 facts = [1]
7
8 def fact_straight(n):
9 r = 1
10 for i in range(2,n):
11 r *= i
12 return r
13
14 def fact(n):
15 global facts
16 return facts[n]
17
18 # precompute facts
19 f = 1
20 for i in range(1,n):
21 f *= i
22 facts.append(f)
23
24 l = 0
25
26 #fact=fact_straight
27
28 for i in xrange(k):
29 for j in xrange(n-k):
30 l+=(fact(i+j)/fact(i)/fact(j))*(fact(k-1)/fact(i)/fact(k-1-i))*(fact(n-k-1)/fact(j)/fact(n-k-1-j))
31
32 # slower!
33 #l+=fact(i+j)*fact(k-1)*fact(n-k-1)/fact(i)/fact(j)/fact(i)/fact(k-i-1)/fact(j)/fact(n-k-j-1)
34
35
36
37
38 print l
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.- [get | view] (2011-09-26 11:35:16, 0.3 KB) [[attachment:Sav_1_cercled_h(~500).py]]
- [get | view] (2011-09-26 11:35:16, 0.5 KB) [[attachment:Sav_2_graphfn(simple, different functions).py]]
- [get | view] (2011-09-26 11:35:16, 0.6 KB) [[attachment:circledot_factorials.py]]
- [get | view] (2011-09-26 11:35:16, 22.8 KB) [[attachment:lines-antialias.png]]
- [get | view] (2011-09-26 11:35:16, 4.3 KB) [[attachment:lines-antialias.py]]
- [get | view] (2011-09-26 11:35:16, 2.0 KB) [[attachment:lines-antialias.seg]]
- [get | view] (2011-09-26 11:35:16, 44.0 KB) [[attachment:lines-antialias2.png]]
- [get | view] (2011-09-26 11:35:16, 2.6 KB) [[attachment:lines-antialias2.seg]]
- [get | view] (2011-09-26 11:35:16, 15.1 KB) [[attachment:lines8.png]]
- [get | view] (2011-09-26 11:35:16, 1.9 KB) [[attachment:lines8.seg]]
You are not allowed to attach a file to this page.