From 4b6fe4b18e38963cd7345e63c4349ad5b1cc6317 Mon Sep 17 00:00:00 2001 From: Morgan Date: Tue, 17 Jan 2023 14:31:06 -0800 Subject: [PATCH] all tests passed --- lib/newman_conway.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/newman_conway.py b/lib/newman_conway.py index 7f5341a..2b77c40 100644 --- a/lib/newman_conway.py +++ b/lib/newman_conway.py @@ -3,4 +3,19 @@ def newman_conway(num): Time Complexity: ? Space Complexity: ? """ - pass + if num <= 0: + raise ValueError + + if num == 1: + return "1" + + if num == 2: + return "1 1" + + seq = [0, 1, 1] + + for i in range(3, num + 1): + cal = seq[seq[i-1]] + seq[i-seq[i-1]] + seq.append(cal) + seq_str = [str(i) for i in seq[1: ]] + return " ".join(seq_str) \ No newline at end of file