2022 day 12.

This commit is contained in:
Mikaël Capelle 2023-12-12 07:32:12 +01:00
parent 1a6ab1cc0e
commit 7151499835
3 changed files with 1032 additions and 1 deletions

View File

@ -1,13 +1,38 @@
import itertools
import sys import sys
from collections import defaultdict from collections import defaultdict
from dataclasses import dataclass from dataclasses import dataclass
from tqdm import tqdm
lines = sys.stdin.read().splitlines() lines = sys.stdin.read().splitlines()
count = 0
for line in lines:
parts = line.split(" ")
pattern = parts[0]
counts = [int(c) for c in parts[1].split(",")]
missing = [i for i in range(len(pattern)) if pattern[i] == "?"]
for replacements in itertools.product(".#", repeat=len(missing)):
c_pattern = list(pattern)
for i_missing, replacement in zip(missing, replacements):
c_pattern[i_missing] = replacement
parts = [p for p in "".join(c_pattern).split(".") if p]
if len(parts) == len(counts) and all(
len(p) == c for p, c in zip(parts, counts)
):
# print("".join(c_pattern), counts)
count += 1
# part 1 # part 1
answer_1 = ... answer_1 = count
print(f"answer 1 is {answer_1}") print(f"answer 1 is {answer_1}")
# part 2 # part 2
answer_2 = ... answer_2 = ...
print(f"answer 2 is {answer_2}") print(f"answer 2 is {answer_2}")
print(f"answer 2 is {answer_2}")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,6 @@
???.### 1,1,3
.??..??...?##. 1,1,3
?#?#?#?#?#?#?#? 1,3,1,6
????.#...#... 4,1,1
????.######..#####. 1,6,5
?###???????? 3,2,1