Skip to content

Instantly share code, notes, and snippets.

@LeoAdamek
Created July 5, 2014 11:47
Show Gist options
  • Save LeoAdamek/b00ecd9380007ee2a666 to your computer and use it in GitHub Desktop.
Save LeoAdamek/b00ecd9380007ee2a666 to your computer and use it in GitHub Desktop.
acks :: [[Int]]
acks = [ [ case (m, n) of
(0, _) -> n + 1
(_, 0) -> acks !! (m - 1) !! 1
(_, _) -> acks !! (m - 1) !! (acks !! m !! (n - 1))
| n <- [0..] ]
| m <- [0..] ]
main :: IO ()
main = print $ acks !! 4 !! 1
module Main where
data P = P !Int !Int
main :: IO ()
main = print $ ack (P 4 1) id
where
ack :: P -> (Int -> Int) -> Int
ack (P 0 n) k = k (n + 1)
ack (P m 0) k = ack (P (m-1) 1) k
ack (P m n) k = ack (P m (n-1)) (\a -> ack (P (m-1) a) k)
main = print $ ack 4 1
where ack :: Int -> Int -> Int
ack 0 n = n+1
ack m 0 = ack (m-1) 1
ack m n = ack (m-1) (ack m (n-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment