From 55c3a31700df7a610357fd1d07fd7b133ad9b78d Mon Sep 17 00:00:00 2001 From: jlee1414 Date: Thu, 15 Dec 2022 13:03:24 -0800 Subject: [PATCH] passing tests --- lib/newman_conway.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 7f5341a..5ef696a 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -1,6 +1,18 @@ def newman_conway(num): - """ Returns a list of the Newman Conway numbers for the given value. - Time Complexity: ? - Space Complexity: ? - """ - pass + if num <= 0: + raise ValueError("Input can't be 0 or less than 0"); + + if num == 1: + return "1" + + p = [0, 1, 1] + + for i in range(3, num + 1): + maths = p[p[i-1]]+p[i-p[i-1]] + p.append(maths); + + p_output= [] + for i in range(1, len(p)): + p_output.append(str(p[i])) + + return " ".join(p_output) \ No newline at end of file