137 Fibonacci golden nuggets.sf 666 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # https://projecteuler.net/problem=137
  6. # Runtime: 0.154s
  7. # I first derived a closed-form to the infinite sum:
  8. #
  9. # -(x / (x^2 + x - 1))
  10. #
  11. # then a reverse to that:
  12. #
  13. # R(x)= (sqrt(5x^2 + 2x +1) - x - 1) / (2x)
  14. #
  15. # after which I discovered that:
  16. #
  17. # R(Fn ∗ F(n+1))= Fn / F(n+1)
  18. #
  19. # simplifying the problem to just:
  20. #
  21. # Fn ∗ F(n+1)
  22. var max = 15
  23. func fib(n) is cached {
  24. n > 1 ? (fib(n-1) + fib(n-2)) : n
  25. }
  26. say (fib(2*max) * fib(2*max + 1))