diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2021-07-12 10:48:31 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2021-07-12 10:48:31 -0400 |
| commit | 34a6514808c066bee4e7f3d7d8bdeb67db056392 (patch) | |
| tree | 05d0e268045ef3d6f971ec0e0c3eb1a48bdb7edd /challenge-075/abigail/python | |
| parent | b59f8f4008bb8ec491a9e89f097f04ce54aed4c0 (diff) | |
| parent | 1aa7b6eaba2a58fc1ef0612373e3aed6b61f345d (diff) | |
| download | perlweeklychallenge-club-34a6514808c066bee4e7f3d7d8bdeb67db056392.tar.gz perlweeklychallenge-club-34a6514808c066bee4e7f3d7d8bdeb67db056392.tar.bz2 perlweeklychallenge-club-34a6514808c066bee4e7f3d7d8bdeb67db056392.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-075/abigail/python')
| -rw-r--r-- | challenge-075/abigail/python/ch-1.py | 29 | ||||
| -rw-r--r-- | challenge-075/abigail/python/ch-2.py | 35 |
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-075/abigail/python/ch-1.py b/challenge-075/abigail/python/ch-1.py new file mode 100644 index 0000000000..8b3ce4f9fb --- /dev/null +++ b/challenge-075/abigail/python/ch-1.py @@ -0,0 +1,29 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py < input-file +# + +import fileinput + +def possibilities (target, coins, first, last): + if target == 0: + return 1 + + if target < 0 or first > last: + return 0 + + sum = 0 + for i in range (1 + int (target / coins [first])): + sum = sum + possibilities (target - i * coins [first], + coins, first + 1, last) + + return sum + +for line in fileinput . input (): + coins = list (map (lambda _: int (_), line . split (" "))) + print (possibilities (coins [0], coins, 1, len (coins) - 1)) diff --git a/challenge-075/abigail/python/ch-2.py b/challenge-075/abigail/python/ch-2.py new file mode 100644 index 0000000000..80045b335c --- /dev/null +++ b/challenge-075/abigail/python/ch-2.py @@ -0,0 +1,35 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput + +for line in fileinput . input (): + heights = list (map (lambda _: int (_), line . split (" "))) + max_height = max (heights) + + max_area = 0 + for h in range (1, max_height + 1): + xam = 0 # max clashes with function max() + cur = 0 + for i in range (0, len (heights)): + if heights [i] >= h: + cur = cur + 1 + else: + if xam < cur: + xam = cur + cur = 0 + if xam < cur: + xam = cur + + area = xam * h + if max_area < area: + max_area = area + + print (max_area) |
