day 12 p2 still got me stumped
This commit is contained in:
parent
0647ea0ca3
commit
2a7a59b949
@ -1,11 +1,11 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
with open('input.text', 'r') as file:
|
with open('test.text', 'r') as file:
|
||||||
data: list[str] = file.readlines()
|
data: list[str] = file.readlines()
|
||||||
|
|
||||||
# Parse Input
|
# Parse Input
|
||||||
|
|
||||||
|
seen = {}
|
||||||
records = []
|
records = []
|
||||||
groups = []
|
groups = []
|
||||||
for line in data:
|
for line in data:
|
||||||
@ -33,11 +33,16 @@ def valid_group(record: str, groups: list[int]) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def check_combinations(record: str, group: list[int]) -> int:
|
def check_combinations(record: str, group: list[int]) -> int:
|
||||||
|
if record in seen:
|
||||||
|
return seen[record]
|
||||||
|
|
||||||
if '?' in record:
|
if '?' in record:
|
||||||
new_record1 = record.replace('?', '.', 1)
|
new_record1 = record.replace('?', '.', 1)
|
||||||
new_record2 = 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:
|
else:
|
||||||
return int(valid_group(record, group))
|
return int(valid_group(record, group))
|
||||||
|
|
||||||
@ -47,4 +52,16 @@ for record, group in zip(records, groups):
|
|||||||
|
|
||||||
print(total)
|
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}')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user