2023 day 13.

This commit is contained in:
Mikaël Capelle 2023-12-13 06:56:15 +01:00
parent 9698dfcdac
commit 8e90bf7002
3 changed files with 1395 additions and 5 deletions

View File

@ -1,13 +1,43 @@
import sys import sys
from collections import defaultdict from typing import Callable, Literal
from dataclasses import dataclass
def split(block: list[str], axis: Literal[0, 1], count: int) -> int:
n_iter = len(block) if axis == 0 else len(block[0])
n_check = len(block) if axis == 1 else len(block[0])
at: Callable[[int, int], str] = (
(lambda i, j: block[i][j]) if axis == 0 else (lambda i, j: block[j][i])
)
for i in range(n_iter - 1):
size = min(i + 1, n_iter - i - 1)
if (
sum(
at(i - s, j) != at(i + 1 + s, j)
for s in range(0, size)
for j in range(n_check)
)
== count
):
return i + 1
return 0
blocks = [block.splitlines() for block in sys.stdin.read().split("\n\n")]
lines = sys.stdin.read().splitlines()
# part 1 # part 1
answer_1 = ... answer_1 = sum(
split(block, axis=1, count=0) + 100 * split(block, axis=0, count=0)
for block in blocks
)
print(f"answer 1 is {answer_1}") print(f"answer 1 is {answer_1}")
# part 2 # part 2
answer_2 = ... answer_2 = sum(
split(block, axis=1, count=1) + 100 * split(block, axis=0, count=1)
for block in blocks
)
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,15 @@
#.##..##.
..#.##.#.
##......#
##......#
..#.##.#.
..##..##.
#.#.##.#.
#...##..#
#....#..#
..##..###
#####.##.
#####.##.
..##..###
#....#..#