[Haskell-begin] Alternating sequence
Dirk Markert
dirk.markert at gmail.com
Mon Jul 21 09:34:12 EDT 2008
I am trying to generate the following list:
2, 3, 5 -- and then alternating (+2) resp (+4) -- 7, 11, 13, 17, 19, 23
I came up with the following solution
2:3:unfoldr (\(a,b) -> Just (a,(a+b, if b == 2 then 4 else 2))) (5,2)
Are there easier ways to generate the desired list?
Dirk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20080721/6a69ff23/attachment-0001.htm
More information about the Beginners
mailing list