Skip to content

Instantly share code, notes, and snippets.

@marcoonroad
Created October 17, 2014 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoonroad/5e9faff916c1e600f6ac to your computer and use it in GitHub Desktop.
Save marcoonroad/5e9faff916c1e600f6ac to your computer and use it in GitHub Desktop.
Multi-Dispatch Ackermann function at Perl 6.
# ~~~ | 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