RosettaCodeData/Task/Ackermann-function/Haskell/ackermann-function-2.hs

11 lines
360 B
Haskell
Raw Permalink Normal View History

2016-12-05 22:15:40 +01:00
import Data.List (mapAccumL)
2013-04-10 12:38:42 -07:00
-- everything here are [Int] or [[Int]], which would overflow
-- * had it not overrun the stack first *
ackermann = iterate ack [1..] where
ack a = s where
2016-12-05 22:15:40 +01:00
s = snd $ mapAccumL f (tail a) (1 : zipWith (-) s (1:s))
f a b = (aa, head aa) where aa = drop b a
2013-04-10 12:38:42 -07:00
main = mapM_ print $ map (\n -> take (6 - n) $ ackermann !! n) [0..5]