reading file to list

André Thieme address.good.until.2009.may.11 at justmail.de
Sun Jan 18 21:24:22 EST 2009


William James schrieb:
> André Thieme wrote:
>
> You make a very strong case that Lisp is very feeble at
> processing data.  I'm almost convinced.

I somehow don’t believe you :-)


> Ruby isn't feeble, so data like this is fine:
> 
> 
> shall we begin?
> or lotus135? 1984 times!
> The 3 stooges: COBOL,LISP,FORTRAN.
> 3.14, si11y L00KING
> 
> 
> Extracting the unsigned integers:
> 
> IO.readlines('data').map{|s| s.scan(/\d+/).map{|s| s.to_i}}
>     ==>[[], [135, 1984], [3], [3, 14, 11, 0]]

Just take the program I posted before and replace
(.split % "\\s")
with
(re-seq #"\d+" %)


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.

Example:
user> (time (nth fibs 900))
"Elapsed time: 16.898726 msecs"

user> (time (nth fibs 901))
"Elapsed time: 0.268603 msecs"


André
-- 



More information about the Python-list mailing list