Skip to content

Instantly share code, notes, and snippets.

@depressed-pho
Created October 30, 2014 05:24
Show Gist options
  • Save depressed-pho/a2a03844653cdae428a3 to your computer and use it in GitHub Desktop.
Save depressed-pho/a2a03844653cdae428a3 to your computer and use it in GitHub Desktop.
Tarai function in Haskell
main :: IO ()
main = print (tarai 13 8 0)
 
tarai :: Int -> Int -> Int -> Int
tarai x y z
| x <= y = y
| otherwise = tarai (tarai (x-1) y z)
(tarai (y-1) z x)
(tarai (z-1) x y)
{-
% ghc --make -O3 Tarai.hs
[1 of 1] Compiling Main ( Tarai.hs, Tarai.o )
Linking Tarai ...
% time ./Tarai
13
./Tarai 0.00s user 0.00s system 95% cpu 0.004 total
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment