From c10e79f3ad4feb2137b3accb1fff4faf64812e75 Mon Sep 17 00:00:00 2001 From: Simon Green Date: Thu, 26 Jan 2023 14:06:10 +1100 Subject: Simon's solution to challenge 201 --- challenge-201/sgreen/python/ch-2.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 challenge-201/sgreen/python/ch-2.py (limited to 'challenge-201/sgreen/python/ch-2.py') 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])) -- cgit