025 1000-digit Fibonacci number.sf 469 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
  6. # https://projecteuler.net/problem=25
  7. # Runtime: 0.163s
  8. func fib_n_digits(n) {
  9. var (f1, f2) = (1, 1);
  10. var i = 2;
  11. loop {
  12. (f1, f2) = (f2, f1+f2)
  13. if (f2.length == n) {
  14. return i+1;
  15. }
  16. ++i
  17. }
  18. }
  19. say fib_n_digits(1000);