Advertisement
chaosagent

Untitled

Dec 9th, 2015
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. import DecInt
  3.  
  4. donecount = 0
  5. gcache = dict()
  6. gcache[0] = DecInt.DecInt(0)
  7. gcache[1] = DecInt.DecInt(1)
  8. def g(x):
  9. if x not in gcache:
  10. gcache[x] = (g(x-1)+g(x-2)).square()
  11. global donecount
  12. donecount += 1
  13. print donecount
  14. return gcache[x]
  15. wcache = dict()
  16. wcache[0] = DecInt.DecInt(0)
  17. wcache[1] = DecInt.DecInt(1)
  18. def w(x):
  19. if x not in wcache:
  20. wcache[x] = (w(x-1)).square() + (w(x-2)).square()
  21. global donecount
  22. donecount += 1
  23. print donecount
  24. return wcache[x]
  25. def f(x):
  26. global donecount
  27. result = g(x)-w(x)
  28. donecount += 1
  29. print donecount, 'f(%d) done' % x
  30. return result
  31. def sumdigits(n):
  32. return sum(map(int, repr(n)[8:-2]))
  33. sdigits = 0
  34. while n:
  35. n, d = divmod(n, 10)
  36. sdigits += d
  37. return sdigits
  38. print sumdigits(f(30))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement