diff options
Diffstat (limited to 'challenge-003/abigail/python')
| -rw-r--r-- | challenge-003/abigail/python/ch-1.py | 27 | ||||
| -rw-r--r-- | challenge-003/abigail/python/ch-2.py | 46 |
2 files changed, 73 insertions, 0 deletions
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 diff --git a/challenge-003/abigail/python/ch-2.py b/challenge-003/abigail/python/ch-2.py new file mode 100644 index 0000000000..9370561d8b --- /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-2.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 + |
