Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
7
Task/Ackermann-function/Haskell/ackermann-function-1.hs
Normal file
7
Task/Ackermann-function/Haskell/ackermann-function-1.hs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
ack :: Int -> Int -> Int
|
||||
ack 0 n = succ n
|
||||
ack m 0 = ack (pred m) 1
|
||||
ack m n = ack (pred m) (ack m (pred n))
|
||||
|
||||
main :: IO ()
|
||||
main = mapM_ print $ uncurry ack <$> [(0, 0), (3, 4)]
|
||||
10
Task/Ackermann-function/Haskell/ackermann-function-2.hs
Normal file
10
Task/Ackermann-function/Haskell/ackermann-function-2.hs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import Data.List (mapAccumL)
|
||||
|
||||
-- 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
|
||||
s = snd $ mapAccumL f (tail a) (1 : zipWith (-) s (1:s))
|
||||
f a b = (aa, head aa) where aa = drop b a
|
||||
|
||||
main = mapM_ print $ map (\n -> take (6 - n) $ ackermann !! n) [0..5]
|
||||
Loading…
Add table
Add a link
Reference in a new issue