From 62a84dafa74e266c44d5889e586cfdfa04910729 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 27 Jan 2021 22:03:31 +0100 Subject: Python solution for week 3, part 1 --- challenge-003/abigail/python/ch-1.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 challenge-003/abigail/python/ch-1.py (limited to 'challenge-003/abigail/python') diff --git a/challenge-003/abigail/python/ch-1.py b/challenge-003/abigail/python/ch-1.py new file mode 100644 index 0000000000..30b41dd8fe --- /dev/null +++ b/challenge-003/abigail/python/ch-1.py @@ -0,0 +1,27 @@ +#!/opt/local/bin/python + +# +# See ../READ.md +# + +# +# Run as python ch-1.py < input-file +# + +import fileinput + +for line in fileinput . input (): + max = int (line) + # + # Python does not have a for (;;) style loop + # + base2 = 1 + while base2 <= max: + base3 = base2 + while base3 <= max: + base5 = base3 + while base5 <= max: + print base5 + base5 *= 5 + base3 *= 3 + base2 *= 2 -- cgit From eda4318efda4548b503c49d8c297047100a5bc27 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 28 Jan 2021 13:56:05 +0100 Subject: Python solution for week 3, part 2 --- challenge-003/abigail/python/ch-2.py | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 challenge-003/abigail/python/ch-2.py (limited to 'challenge-003/abigail/python') diff --git a/challenge-003/abigail/python/ch-2.py b/challenge-003/abigail/python/ch-2.py new file mode 100644 index 0000000000..fe5b1aa5e3 --- /dev/null +++ b/challenge-003/abigail/python/ch-2.py @@ -0,0 +1,46 @@ +#!/opt/local/bin/python + +# +# See ../READ.md +# + +# +# Run as python ch-1.py < input-file +# + +import fileinput +import sys + +# +# Iterate over the input +# +for line in fileinput . input (): + rows = int (line) + + # + # Create the first row, and print it + # + row = [1] + sys . stdout . write (str (1) + "\n") + + for r in range (1, rows + 1): + # + # Create a new row + # + new = [None] * (r + 1) # In Python, arrays don't grow automatically + for i in range (r + 1): + sum = 0 + if i > 0: + sum = row [i - 1] + sys . stdout . write (" ") + if i < r: + sum = sum + row [i] + new [i] = sum + sys . stdout . write (str (sum)) + sys . stdout . write ("\n") + + # + # New row becomes current row + # + row = new + -- cgit From 94e384b4b3ad6812bc5d36ad1fc56456f029e0cd Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 28 Jan 2021 14:23:27 +0100 Subject: Fix references to self --- challenge-003/abigail/python/ch-2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'challenge-003/abigail/python') diff --git a/challenge-003/abigail/python/ch-2.py b/challenge-003/abigail/python/ch-2.py index fe5b1aa5e3..9370561d8b 100644 --- a/challenge-003/abigail/python/ch-2.py +++ b/challenge-003/abigail/python/ch-2.py @@ -5,7 +5,7 @@ # # -# Run as python ch-1.py < input-file +# Run as python ch-2.py < input-file # import fileinput -- cgit