Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. 1 2 3
  2. 4 5 6
  3. 7 8 9
  4.  
  5. 1
  6. 3
  7. 7,2,3
  8. 1,5,9,2
  9. 1,8,6,5,4
  10. 4,2,3,5,6,7,8,9
  11. 5,9,6,4
  12.  
  13. 1,3
  14. 1,9,5
  15. 7,5,4,7
  16. 4,6
  17.  
  18. (M,N,d)
  19.  
  20. 1 <= M <= 16
  21. 1 <= N <= 16
  22. 1 <= d <= M * N
  23.  
  24. Input: 2,2,1
  25. Output: 4
  26. Input: 2,2,2
  27. Output: 12
  28. Input: 7,4,1
  29. Output: 28
  30.  
  31. //If I've made a mistake or the rules are unclear, please correct me!
  32.  
  33. from fractions import*
  34. p=lambda m,n,d,l=0,s=set():d<1or sum([p(m,n,d-1,i,s|{i})for i in range(m*n)if not(s and(s&{i}or set(range(l,i,abs(i-l)/gcd(i%n-l%n,i/n-l/n)))-s))])
  35.  
  36. for i in range(4, 10):
  37. print p(3, 3, i)
  38.  
  39. 1624
  40. 7152
  41. 26016
  42. 72912
  43. 140704
  44. 140704
  45.  
  46. 20
  47. 262
  48. 3280
  49. 39644
  50. 459764
  51. 5101232
  52.  
  53. if not(s and(s&{i}or set(range(l,i,abs(i-l)/gcd(i%n-l%n,i/n-l/n)))-s))
  54.  
  55. If no pegs have been used yet
  56. OR
  57. the target peg has not yet been used
  58. AND
  59. each of the pegs directly between the target peg and the
  60. current peg (a.k.a. "jumped over") have already been used
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement