From 5b33171dd6437ba00a6362541b86e82574df0489 Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Mon, 4 Mar 2019 20:47:01 +0000 Subject: [PATCH] Add incorrect ackermann implementation and tests --- 2_troubleshooting.py | 17 +++++++++++++++++ ackermann_attempt.py | 13 +++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 2_troubleshooting.py create mode 100644 ackermann_attempt.py diff --git a/2_troubleshooting.py b/2_troubleshooting.py new file mode 100644 index 0000000..e4b91c6 --- /dev/null +++ b/2_troubleshooting.py @@ -0,0 +1,17 @@ +from ackermann_attempt import incorrect_ackermann + + +def test_ackermann_3_3(): + assert incorrect_ackermann(3, 3) == 61 + +def test_ackermann_0_0(): + assert incorrect_ackermann(0, 0) == 1 + +def test_ackermann_4_0(): + assert incorrect_ackermann(4, 0) == 13 + +def test_ackermann_0_4(): + assert incorrect_ackermann(0, 4) == 5 + +def test_ackermann_3_5(): + assert incorrect_ackermann(3, 5) == 253 diff --git a/ackermann_attempt.py b/ackermann_attempt.py new file mode 100644 index 0000000..3c2ba73 --- /dev/null +++ b/ackermann_attempt.py @@ -0,0 +1,13 @@ +def incorrect_ackermann(m, n): + if m == 0: + return m + 1 + elif m > 0 and n == 0: + return incorrect_ackermann(m - 1, 1) + else: + return incorrect_ackermann(m - 1, incorrect_ackermann(m - 1, n - 1)) + + + +# if m == 0 -> n+1 +# if m > 0 and n == 0 -> A(m-1, 1) +# otherwise -> A(m-1, A(m, n - 1) -- 2.44.0