Last active
July 14, 2018 20:34
-
-
Save JacoMalan1/7587f4cd18952d47c5dc879533dec98a to your computer and use it in GitHub Desktop.
Ackerman in Haskell (Jaco Malan)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A program to calculate the values of Ackerman's function from (0, 0) to (5, 5). | |
-- Copyright (C) 2018 Jaco Malan | |
-- This program is free software: you can redistribute it and/or modify | |
-- it under the terms of the GNU General Public License as published by | |
-- the Free Software Foundation, either version 3 of the License, or | |
-- (at your option) any later version. | |
-- This program is distributed in the hope that it will be useful, | |
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
-- GNU General Public License for more details. | |
-- You should have received a copy of the GNU General Public License | |
-- along with this program. If not, see <https://www.gnu.org/licenses/>. | |
ack :: (Integer, Integer) -> Integer | |
ack (m, n) | |
| m == 0 = n + 1 | |
| n == 0 && m > 0 = ack (m - 1, 1) | |
| m > 0 && n > 0 = ack (m - 1, ack (m, n - 1)) | |
main :: IO () | |
main = do | |
let nums = concatMap (\m -> map (\n -> (m, n)) [0..5]) [0..5] | |
let ans = map (\m -> "Ackerman " ++ show m ++ ": " ++ (show . ack) m) nums | |
mapM_ putStrLn ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ackerman's function
Ackerman's function is a famous function in computer science which proves that some tasks cannot be de-recursed (broken down into loops).
Compiling
$ ghc main.hs
optionally use '-O' for optimizations since this is a heavily CPU-intensive program.Licensing
This gist is licensed under the GNU GPL v3.0.
Author: Jaco Malan