065 Convergents of e.sf 487 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # Find the sum of digits in the numerator of the 100th convergent of the continued fraction for e.
  6. # https://projecteuler.net/problem=65
  7. # Runtime: 0.112s
  8. func e(n, i=1) {
  9. return 0 if (i >= n)
  10. 1/(
  11. 1 + 1/(
  12. 2*i + 1/(
  13. 1 + e(n, i+1)
  14. )
  15. )
  16. )
  17. }
  18. var n = 100
  19. var frac = 2+e(int(n/3 + 1))
  20. say frac.numerator.sumdigits