From: Sebastian Hungerecker Date: 2009-01-19T18:59:28+09:00 Subject: Re: reading file to list André Thieme wrote: > Now that I was so kind to give you what you asked for, you will > probably do the same for me and show me your Ruby code, in which you > define a variable that contains the Fibonacci sequence. > > (def fibs (lazy-cat [0 1] (map + fibs (drop 1 fibs)))) > > > (nth fibs 70) ==> 190392490709135 > > One requirement is that when you look at the n'th fib the results up > to n must be memoized, so that nothing needs to be calculated again > when you ask for a fib between 0 and n. And when you ask for the n+1'th > it will start the calculation right from point n. fibs = Hash.new {|h,k| h[k] = h[k-1] + h[k-2]}.merge(0=>0, 1=>1) fibs[70] #=> 190392490709135 HTH, Sebastian -- Jabber: sepp2k@jabber.org ICQ: 205544826