Created
October 17, 2014 19:49
-
-
Save marcoonroad/5e9faff916c1e600f6ac to your computer and use it in GitHub Desktop.
Multi-Dispatch Ackermann function at Perl 6.
This file contains 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
# ~~~ | n + 1 :@: if m = 0 ~~~ # | |
# ~~~ A(m, n) = | A(m - 1, 1) :@: if m > 0 and n = 0 ~~~ # | |
# ~~~ | A(m - 1, A(m, n - 1) :@: if m > 0 and n > 0 ~~~ # | |
multi A($m where(* == 0), $n ) { $n + 1 } | |
multi A($m where(* > 0), $n where(* == 0)) { A($m - 1, 1) } | |
multi A($m where(* > 0), $n where(* > 0)) { A($m - 1, A($m, $n - 1)) } | |
say A(1, 2); | |
# say A(4, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment