Ackermann function: Difference between revisions
Content added Content deleted
imported>Tromp (Add BLC Ackermann function on Church numerals) |
(Add bruijn) |
||
Line 1,871: | Line 1,871: | ||
p ackermann 3, 4 #Prints 125</syntaxhighlight> |
p ackermann 3, 4 #Prints 125</syntaxhighlight> |
||
=={{header|Bruijn}}== |
|||
<syntaxhighlight lang="bruijn">:import std/Combinator . |
|||
:import std/Number/Unary U |
|||
:import std/Math . |
|||
# unary ackermann |
|||
ackermann-unary [0 [[U.inc 0 1 (+1u)]] U.inc] |
|||
:test (ackermann-unary (+0u) (+0u)) ((+1u)) |
|||
:test (ackermann-unary (+3u) (+4u)) ((+125u)) |
|||
# ternary ackermann (lower space complexity) |
|||
ackermann-ternary y [[[=?1 ++0 (=?0 (2 --1 (+1)) (2 --1 (2 1 --0)))]]] |
|||
:test ((ackermann-ternary (+0) (+0)) =? (+1)) ([[1]]) |
|||
:test ((ackermann-ternary (+3) (+4)) =? (+125)) ([[1]])</syntaxhighlight> |
|||
=={{header|C}}== |
=={{header|C}}== |