-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from wimglenn/2023/12
2023/12
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" | ||
--- Day 12: Hot Springs --- | ||
https://adventofcode.com/2023/day/12 | ||
""" | ||
from aocd import data | ||
from functools import cache | ||
|
||
|
||
@cache | ||
def fits(ss, cs, h=0): | ||
if not any(cs): | ||
return "#" not in ss | ||
if not ss: | ||
return 0 | ||
c, cs = cs[-1], cs[:-1] | ||
s, ss = ss[-1], ss[:-1] | ||
if not c: | ||
return (s != "#") and fits(ss, cs, 0) | ||
if h: | ||
return (s != ".") and fits(ss, (*cs, c-1), 1) | ||
if s == "#": | ||
return fits(ss, (*cs, c - 1), 1) | ||
if s == ".": | ||
return fits(ss, (*cs, c), 0) | ||
if s == "?": | ||
return fits(ss, (*cs, c), 0) + fits(ss, (*cs, c - 1), 1) | ||
|
||
|
||
a = b = 0 | ||
for line in data.splitlines(): | ||
template_a, counts = line.split() | ||
counts_a = *map(int, counts.split(",")), | ||
template_b = "?".join([template_a]*5) | ||
counts_b = counts_a*5 | ||
a += fits(template_a, counts_a) | ||
b += fits(template_b, counts_b) | ||
|
||
print("answer_a:", a) | ||
print("answer_b:", b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
???.### 1,1,3 | ||
.??..??...?##. 1,1,3 | ||
?#?#?#?#?#?#?#? 1,3,1,6 | ||
????.#...#... 4,1,1 | ||
????.######..#####. 1,6,5 | ||
?###???????? 3,2,1 | ||
21 | ||
525152 |