itai12345

euler114.py

Jun 6th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. #-3= -1-2 for 1,2 don't count
  2. #+1 = none at all scenario
  3. import math
  4. n=50
  5. sum1=((n*(n-2))/8)+1
  6. print sum1
  7. sum = 0
  8. for i in range(3, int(n/2)):
  9.     print "i:",i
  10.     for k in range(2, int(n/i)+1):#one block of three, two blocks, etc
  11.         print "k:",k
  12.         slots = k+1
  13.         stones = n-(i*k)-(k-1)
  14.         if(slots-stones >= 0 and stones>=0):
  15.             sum += math.factorial(slots)/(math.factorial(slots-stones)*math.factorial(stones))
  16.         elif(slots==stones):
  17.             sum+=1
  18. print sum+sum1
Advertisement
Add Comment
Please, Sign In to add comment