ShareMyScreen/ProjectEuler/0025

From J Wiki
Jump to navigation Jump to search

What is the index of the first Fibonacci number to have 1000 digits?

Admittedly, there are better ways of solving this using ^:_1 rather than having to up one's y until one hits upon the first 1000-digit one.

   >: (i. 1e3"_) # @ ": "0 {{ (] , [: +/ (_1 _2)&{) ^: (y-2) (1x&, ^: 2)''}} 6e3

   {{ (] , [: +/ (_1 _2)&{) ^: (y-2) (1x&, ^: 2)''}} NB. this explicit verb generates the first y Fibonacci series members, where y>=3
   (1x&, ^: 2)''                                     NB. extended precision, because growth is rapid, begin by appending two 1s to nothing
   ] ^: (y-2)                                        NB. because we have the first two members, y-2 sequent members are calculated
   (] , [: +/ (_1 _2)&{)                             NB. append the present series members to the sum of the last two
   # @ ": "0                                         NB. length of string of each of number
   >: (i. 1e3"_)                                     NB. index of 1000 (represented as an infinite rank verb because that's how the train is); as site counts from 1, increment