123456789101112131415161718192021222324252627 |
- #!/usr/bin/ruby
- # Author: Daniel "Trizen" Șuteu
- # License: GPLv3
- # Website: https://github.com/trizen
- # What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
- # https://projecteuler.net/problem=25
- # Runtime: 0.163s
- func fib_n_digits(n) {
- var (f1, f2) = (1, 1);
- var i = 2;
- loop {
- (f1, f2) = (f2, f1+f2)
- if (f2.length == n) {
- return i+1;
- }
- ++i
- }
- }
- say fib_n_digits(1000);
|