aboutsummaryrefslogtreecommitdiff
path: root/challenge-325/ysth/python/ch-2.py
diff options
context:
space:
mode:
authorYitzchak Scott-Thoennes <sthoenna@gmail.com>2025-06-11 20:42:24 -0400
committerYitzchak Scott-Thoennes <sthoenna@gmail.com>2025-06-15 16:19:29 -0400
commitb5d49aa06286a39fe7011326e7c0db5822d5f33c (patch)
treef5b4281e83697ca2e1ef21487e4928c4d771a5a5 /challenge-325/ysth/python/ch-2.py
parent38b214c5d2eee86db7573b3a783e90b45d52a769 (diff)
downloadperlweeklychallenge-club-b5d49aa06286a39fe7011326e7c0db5822d5f33c.tar.gz
perlweeklychallenge-club-b5d49aa06286a39fe7011326e7c0db5822d5f33c.tar.bz2
perlweeklychallenge-club-b5d49aa06286a39fe7011326e7c0db5822d5f33c.zip
challenge 325 python and perl solutons by ysth
Diffstat (limited to 'challenge-325/ysth/python/ch-2.py')
-rw-r--r--challenge-325/ysth/python/ch-2.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-325/ysth/python/ch-2.py b/challenge-325/ysth/python/ch-2.py
new file mode 100644
index 0000000000..f151496925
--- /dev/null
+++ b/challenge-325/ysth/python/ch-2.py
@@ -0,0 +1,18 @@
+import sys
+import bisect
+
+prices = [int(value) for value in sys.argv[1:]]
+
+
+sale_prices = []
+seen_prices = []
+for price in reversed(prices):
+ seen_price_index = bisect.bisect_right(seen_prices, price)
+ discount = seen_prices[seen_price_index-1] if seen_price_index > 0 else 0
+ if seen_price_index == 0 or seen_prices[seen_price_index-1] != price:
+ seen_prices[seen_price_index:] = [price]
+ sale_prices.insert(0, price - discount)
+
+
+print("prices: ", prices)
+print("sale prices ", sale_prices)