2023/day12 #1

Merged
mikael.capelle merged 5 commits from 2023/day12 into master 2023-12-12 20:20:27 +00:00
3 changed files with 1032 additions and 1 deletions
Showing only changes of commit 7151499835 - Show all commits

View File

@ -1,13 +1,38 @@
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 = ...
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}")

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