From 5db4f5c0159d59599c5d39d41ac44854e70c8830 Mon Sep 17 00:00:00 2001 From: PedroEdiaz Date: Wed, 29 Oct 2025 23:26:33 -0600 Subject: [PATCH] Add: 10->12, 17 --- 2015/10.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2015/11.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2015/12.py | 37 +++++++++++++++++++++++++++++++++++++ 2015/17.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 173 insertions(+) create mode 100644 2015/10.py create mode 100644 2015/11.py create mode 100644 2015/12.py create mode 100644 2015/17.py diff --git a/2015/10.py b/2015/10.py new file mode 100644 index 0000000..24d7869 --- /dev/null +++ b/2015/10.py @@ -0,0 +1,46 @@ +input = "1" + +def look_and_say(input): + s = "" + last = 'x' + count = 1 + + for n in input: + if last == 'x': + last = n + count = 1 + continue; + + if last == n: + count += 1 + continue; + + s+=f"{count}{last}" + + last=n + count=1 + + return s+f"{count}{n}" + + +""" Not worth it +def recursive_look_and_say(input): + j = len(input)//2 + + while True: + if j == len(input)-1: + return look_and_say(input) + + # Assert 'j' does not divide repeating characters + if input[j] != input[j+1]: + return recursive_look_and_say(input[:j+1])+ recursive_look_and_say(input[j+1:]) + + j+=1 +""" + + +# Result + +for i in range(50): + input = look_and_say(input) +print(len(input)) diff --git a/2015/11.py b/2015/11.py new file mode 100644 index 0000000..cb38789 --- /dev/null +++ b/2015/11.py @@ -0,0 +1,47 @@ +import re + +input = "cqjxjnds" + +def match(pattern, string): + return re.search(pattern, string) != None + +def rule1(input): + matched = 0 + last = '-' + + for c in input: + if ord(c) == ord(last) + 1: + matched += 1 + if matched == 3: + return True + else: + matched = 1 + + last = c + + + return False + + +def increment(input): + res = "" + carry = 1 + + for c in reversed(input): + if carry != 0: + if c=='z': + c = chr(ord('a')) + carry = carry + else: + c = chr(ord(c)+carry) + carry = 0 + res = c + res + + return res + + +for i in range(10): + while not (rule1(input) and match(r"(.)\1.*(.)\2", input) and not match(r"i|o|l", input)): + input = increment(input) + print(input) + input = increment(input) diff --git a/2015/12.py b/2015/12.py new file mode 100644 index 0000000..b9b54da --- /dev/null +++ b/2015/12.py @@ -0,0 +1,37 @@ +import json + +# Fill Input + +try: + with open("12.txt", 'r', encoding='utf-8') as file: + input = json.load(file) +except Exception as e: + print(f"An error occurred: {e}") + +# Convert Corrdenate to string + +def recursive_decend(json:any)->int: + match json: + case dict(): + sum = 0; + for i in json: + """ Part 2 + if json[i] == "red": + return 0 + """ + + sum += recursive_decend(json[i]) + return sum + case list(): + sum = 0; + for i in json: + sum += recursive_decend(i) + return sum + case int(): + return json + case str(): + return 0; + +print(recursive_decend(input)) + + diff --git a/2015/17.py b/2015/17.py new file mode 100644 index 0000000..92c614f --- /dev/null +++ b/2015/17.py @@ -0,0 +1,43 @@ +# Fill Input + +input = "" + +try: + with open("17.txt", 'r', encoding='utf-8') as file: + input += file.read() +except Exception as e: + print(f"An error occurred: {e}") + +# Check if sum of permutation equal 150 +def sum_equal_150(input, i): + sum = 0 + for j in range(l): + if i & 1< 150: + return False + return sum == 150 + +# Reverse sort input +input= [ int(x) for x in input.split()] +input.sort(reverse=True) + +l = len(input) +res1, res2, min_popcount = 0, 0, l + +for i in range(2**l): + if not sum_equal_150(input, i): + continue + + popcount = i.bit_count() + + if popcount < min_popcount: + min_popcount = popcount + res2 = 0; + + if popcount == min_popcount: + res2 += 1; + + res1 += 1 + +print(res1, res2)