From b5d49aa06286a39fe7011326e7c0db5822d5f33c Mon Sep 17 00:00:00 2001 From: Yitzchak Scott-Thoennes Date: Wed, 11 Jun 2025 20:42:24 -0400 Subject: challenge 325 python and perl solutons by ysth --- challenge-325/ysth/python/ch-1.py | 58 +++++++++++++++++++++++++++++++++++++++ challenge-325/ysth/python/ch-2.py | 18 ++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 challenge-325/ysth/python/ch-1.py create mode 100644 challenge-325/ysth/python/ch-2.py (limited to 'challenge-325/ysth/python') diff --git a/challenge-325/ysth/python/ch-1.py b/challenge-325/ysth/python/ch-1.py new file mode 100644 index 0000000000..97aa83a7a3 --- /dev/null +++ b/challenge-325/ysth/python/ch-1.py @@ -0,0 +1,58 @@ +import sys + +#https://stackoverflow.com/questions/65271060/is-there-a-built-in-way-to-use-inline-c-code-in-python + +# cffi? https://stackoverflow.com/questions/65271060/is-there-a-built-in-way-to-use-inline-c-code-in-python +# python benchmarks + +# ch-2: perl using List::BinarySearch and Judy1 + +def make_regex_search(r): + def regex_search(binary_list): + match = r.search(''.join(['1' if value==1 else '0' for value in binary_list])) + result = 0 if not match else len(match.group(1)) + return result + return regex_search + +import re +naive_regex = make_regex_search(re.compile('(1+)(?!.*?\\1)')) + +better_regex = make_regex_search(re.compile('(? 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) -- cgit