Re: [Haskell-cafe] About Fibonacci again...

2007-11-08 Thread Bernie Pope
You can make it pretty short too, if you allow yourself fix: rs=1:fix(\f p n-n++f(p++n)p)[1][0] I came up with this on the train home, but then I realised it was the same as your solution :) On 08/11/2007, at 12:57 PM, Alfonso Acosta wrote: How about this, infiniteRS :: [Int]

Re: [Haskell-cafe] About Fibonacci again...

2007-11-08 Thread jerzy . karczmarczuk
Report from the Rabbit Warren. Thank you, everybody, for your contribution. The problem was, how to construct a one-liner which generates the infinite Rabbit Sequence: 10110101101101011010110110101101101011010110110101101011011010110... This is the result of an *infinite time* evolution of a

Re: [Haskell-cafe] About Fibonacci again...

2007-11-08 Thread Yitzchak Gale
rabbit = 1 : concatMap ((0:) . flip replicate 1 . (1+)) rabbit This nasty acquaintance of mine... demanded the solution (in Haskell) as a one-liner. It wasn't you yourself, was it? No. Please, tell me it isn't so. Regards, Yitz ___ Haskell-Cafe

Re: [Haskell-cafe] About Fibonacci again...

2007-11-08 Thread Henning Thielemann
On Thu, 8 Nov 2007 [EMAIL PROTECTED] wrote: Report from the Rabbit Warren. Thank you, everybody, for your contribution. The problem was, how to construct a one-liner which generates the infinite Rabbit Sequence: 10110101101101011010110110101101101011010110110101101011011010110... This is

Re: [Haskell-cafe] About Fibonacci again...

2007-11-08 Thread Stuart Cook
On 11/8/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have a vague impression that the solution of Alfonso Acosta: rs_aa = let acum a1 a2 = a2 ++ acum (a1++a2) a1 in 1 : acum [1] [0] is also somehow related to this limit stuff, although it is simpler, and formulated differently. I

Re: [Haskell-cafe] About Fibonacci again...

2007-11-08 Thread Thomas Schilling
On Thu, 2007-11-08 at 00:56 +0100, [EMAIL PROTECTED] wrote: Don't shoot me... The last exchange with Andrew Bromage made me recall a homework which was given to some students by a particularly nasty teacher I happen to know. The question is to generate the whole infinite Rabbit Sequence

Re: [Haskell-cafe] About Fibonacci again...

2007-11-08 Thread jerzy . karczmarczuk
Henning Thielemann writes: And now we have much Haskell code for one sequence to be submitted to the Online Encyclopedia of Integer Sequences! Is there anything really there in Haskell?... Well, if you are interested in something more venerable than rabbits, why not try the sequence which

[Haskell-cafe] About Fibonacci again...

2007-11-07 Thread jerzy . karczmarczuk
Don't shoot me... The last exchange with Andrew Bromage made me recall a homework which was given to some students by a particularly nasty teacher I happen to know. The question is to generate the whole infinite Rabbit Sequence in one shot (co-recursive, selbstverständlich). The Rabbit

Re: [Haskell-cafe] About Fibonacci again...

2007-11-07 Thread ajb
G'day all. Quoting [EMAIL PROTECTED]: This nasty acquaintance of mine asked the students to write down a simple procedure which generates the sequence after the infinite number of units of time. Cool problem! Simple is, of course, in the eye of the beholder. zipWith (!!) (fix (([1]:).map(=

Re: [Haskell-cafe] About Fibonacci again...

2007-11-07 Thread Stuart Cook
On 11/8/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Would somebody try to solve it, before I unveil the solution? It isn't difficult. *** SPOILER WARNING *** Here's my attempt, which I wrote without peeking: let fibs' = 1 : 2 : zipWith (+) fibs' (tail fibs') rabbits = 1 : 0 :

Re: [Haskell-cafe] About Fibonacci again...

2007-11-07 Thread Ross Paterson
On Thu, Nov 08, 2007 at 12:56:46AM +0100, [EMAIL PROTECTED] wrote: This nasty acquaintance of mine asked the students to write down a simple procedure which generates the sequence after the infinite number of units of time. Of course, any finite prefix of it. rabbit = let rs = 0 : [x | r - rs,

Re: [Haskell-cafe] About Fibonacci again...

2007-11-07 Thread Alfonso Acosta
How about this, infiniteRS :: [Int] infiniteRS = let acum a1 a2 = a2 ++ acum (a1++a2) a1 in 1 : acum [1] [0] it certainly fits in one line but it's not really elegant ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] About Fibonacci again...

2007-11-07 Thread ajb
G'day all. Quoting [EMAIL PROTECTED]: zipWith (!!) (fix (([1]:).map(= \x-if x==0 then [1] else [1,0]))) [0..] This was the shortest variant I could manage in the time allotted: zipWith(!!)(fix(([1]:).map(= \x-1:[0|x==1])))[0..] Cheers, Andrew Bromage

Re: [Haskell-cafe] About Fibonacci again...

2007-11-07 Thread Bernie Pope
Is this what you are looking for: mrs = [0] : [1] : zipWith (++) (tail mrs) mrs then you can get the one you want with: mrs !! index given a suitable value for index It seems I didn't read the question carefully - you want the infinite list. You can recover the solution from mrs