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