day 12 p2 still got me stumped

This commit is contained in:
JISAUAY 2024-12-05 16:09:59 -06:00
parent 0647ea0ca3
commit 2a7a59b949
3 changed files with 20 additions and 3 deletions

View File

@ -1,11 +1,11 @@
import re
with open('input.text', 'r') as file:
with open('test.text', 'r') as file:
data: list[str] = file.readlines()
# Parse Input
seen = {}
records = []
groups = []
for line in data:
@ -33,11 +33,16 @@ def valid_group(record: str, groups: list[int]) -> bool:
return True
def check_combinations(record: str, group: list[int]) -> int:
if record in seen:
return seen[record]
if '?' in record:
new_record1 = record.replace('?', '.', 1)
new_record2 = record.replace('?', '#', 1)
return check_combinations(new_record1, group) + check_combinations(new_record2, group)
ans = check_combinations(new_record1, group) + check_combinations(new_record2, group)
seen[record] = ans
return ans
else:
return int(valid_group(record, group))
@ -47,4 +52,16 @@ for record, group in zip(records, groups):
print(total)
# Part 2
total = 0
for record, group in zip(records, groups):
record = ((record + '?')* 5)[:-1]
group = group * 5
total += check_combinations(record, group)
print(f'Part 2: {total}')