From: Christian Neukirchen Date: 2006-06-27T05:48:38+09:00 Subject: Re: [QUIZ] pp Pascal (#84) "Paul Battley" writes: > On 25/06/06, Christian Neukirchen wrote: >> Given this, I can't resist but "break the rules" even further---by not >> even writing the solution in Ruby. ;-) It's pretty nice to do in Haskell: >> >> > pascal = iterate (\last -> zipWith (+) ([0] ++ last) (last ++ [0])) [1] >> > >> > pp n = mapM_ (putStrLn . join "|" . map (show)) $ take n $ pascal >> > where join s (x:xs) | xs == [] = x >> > | otherwise = x ++ s ++ join s xs >> > > Aha! I had a go at it in Haskell, too, and used the same zipWith technique. Nice to see you doing Haskell... :-) > Actually, that got me thinking: why doesn't zip in Ruby take a block? > It could handle Haskell's zip (and zip3 etc.) *and* zipWith then... It actually takes a block, but only yields and doesn't map. It would take a lot of memory if it had to map in every case---not sure that is a good reason, though. > Paul. -- Christian Neukirchen http://chneukirchen.org