From a4c87ef16830fc56ab6b6115de8d58f76cba1a4d Mon Sep 17 00:00:00 2001 From: Victoria Shade Date: Thu, 19 Jan 2023 20:34:48 -0800 Subject: [PATCH] solution w/tests passing --- lib/newman_conway.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 7f5341a..953f202 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -3,4 +3,21 @@ def newman_conway(num): Time Complexity: ? Space Complexity: ? """ - pass + + if num <= 0: + raise ValueError("Input cannot be 0 or less") + + if num == 1: + return "1" + + if num == 2: + return "1 1" + + sequence = [0, 1, 1] + + for i in range(3, num + 1): + calculate = sequence[sequence[i - 1]] + sequence[i - sequence[i - 1]] + sequence.append(calculate) + + sequence_string = [str(i) for i in sequence[1: ]] + return " ".join(sequence_string) \ No newline at end of file