advent-of-code/2023/day12.py
Mikaël Capelle 7151499835 2022 day 12.
2023-12-12 07:46:34 +01:00

39 lines
979 B
Python

import itertools
import sys
from collections import defaultdict
from dataclasses import dataclass
from tqdm import tqdm
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
answer_1 = count
print(f"answer 1 is {answer_1}")
# part 2
answer_2 = ...
print(f"answer 2 is {answer_2}")
print(f"answer 2 is {answer_2}")