123456789101112131415161718192021222324252627282930 |
- #!/usr/bin/ruby
- # Author: Daniel "Trizen" Șuteu
- # License: GPLv3
- # Website: https://github.com/trizen
- # Find the sum of digits in the numerator of the 100th convergent of the continued fraction for e.
- # https://projecteuler.net/problem=65
- # Runtime: 0.112s
- func e(n, i=1) {
- return 0 if (i >= n)
- 1/(
- 1 + 1/(
- 2*i + 1/(
- 1 + e(n, i+1)
- )
- )
- )
- }
- var n = 100
- var frac = 2+e(int(n/3 + 1))
- say frac.numerator.sumdigits
|