From d487813d5b1b35bf20b5f5789424a67f9d37f0b0 Mon Sep 17 00:00:00 2001 From: Amber Date: Thu, 12 Jan 2023 15:02:51 -0800 Subject: [PATCH] completed passing all tests --- lib/newman_conway.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 7f5341a..c08cb71 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -3,4 +3,16 @@ def newman_conway(num): Time Complexity: ? Space Complexity: ? """ - pass + if num <= 0: + raise ValueError + result = [] + for i in range(1,num+1): + result.append(sequence(i)) + return " ".join(str(n) for n in result) + +def sequence(i): + if i == 1 or i == 2: + return 1 + else: + next = sequence(sequence(i-1)) + sequence(i-sequence(i-1)) + return next