aboutsummaryrefslogtreecommitdiff
path: root/challenge-201/sgreen/python
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2023-01-26 14:06:10 +1100
committerSimon Green <mail@simon.green>2023-01-26 14:06:10 +1100
commitc10e79f3ad4feb2137b3accb1fff4faf64812e75 (patch)
tree5776e42f46e16d077e841e47c9e6fa68d551b9bb /challenge-201/sgreen/python
parent27b88f614b9bb53872ef0da19a56087505836db0 (diff)
downloadperlweeklychallenge-club-c10e79f3ad4feb2137b3accb1fff4faf64812e75.tar.gz
perlweeklychallenge-club-c10e79f3ad4feb2137b3accb1fff4faf64812e75.tar.bz2
perlweeklychallenge-club-c10e79f3ad4feb2137b3accb1fff4faf64812e75.zip
Simon's solution to challenge 201
Diffstat (limited to 'challenge-201/sgreen/python')
-rwxr-xr-xchallenge-201/sgreen/python/ch-1.py15
-rwxr-xr-xchallenge-201/sgreen/python/ch-2.py24
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-201/sgreen/python/ch-1.py b/challenge-201/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..e42e28f11c
--- /dev/null
+++ b/challenge-201/sgreen/python/ch-1.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ # Find numbers between 0 and the length of n that don't appear in the input
+ missing = [i for i in range(len(n)+1) if i not in n]
+ print(*missing, sep=', ')
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)
diff --git a/challenge-201/sgreen/python/ch-2.py b/challenge-201/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..9899aa8557
--- /dev/null
+++ b/challenge-201/sgreen/python/ch-2.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def pile(remain, minimum):
+ found = 0
+ for take in range(minimum, remain+1):
+ if remain == take:
+ # We have a solution
+ found += 1
+ else:
+ # Take this amount from the remaining pennies
+ found += pile(remain - take, take)
+
+ return found
+
+
+def main(n):
+ print(pile(n, 1))
+
+
+if __name__ == '__main__':
+ main(int(sys.argv[1]))