[py] Solve 2024_04 part 1
This commit is contained in:
parent
74d10cd770
commit
281a027857
9 changed files with 196 additions and 1 deletions
|
|
@ -2,7 +2,7 @@ import argparse
|
|||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from . import y2015, y2016, y2017, y2018, y2020, y2021, y2022
|
||||
from . import y2015, y2016, y2017, y2018, y2020, y2021, y2022, y2024
|
||||
|
||||
DAYS = {
|
||||
**y2015.DAYS,
|
||||
|
|
@ -12,6 +12,7 @@ DAYS = {
|
|||
**y2020.DAYS,
|
||||
**y2021.DAYS,
|
||||
**y2022.DAYS,
|
||||
**y2024.DAYS,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
5
py/aoc/y2024/__init__.py
Normal file
5
py/aoc/y2024/__init__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from . import d04
|
||||
|
||||
DAYS = {
|
||||
"2024_04": d04.solve,
|
||||
}
|
||||
31
py/aoc/y2024/d04.py
Normal file
31
py/aoc/y2024/d04.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
def mirror_h(lines):
|
||||
return [line[::-1] for line in lines]
|
||||
|
||||
|
||||
def mirror_v(lines):
|
||||
return lines[::-1]
|
||||
|
||||
|
||||
def transpose(lines):
|
||||
return ["".join(chars) for chars in zip(*lines)]
|
||||
|
||||
|
||||
def shift(lines):
|
||||
return [" " * i + line + " " * (len(lines) - 1 - i) for i, line in enumerate(lines)]
|
||||
|
||||
|
||||
def count_xmas(lines):
|
||||
return sum(line.count("XMAS") for line in lines)
|
||||
|
||||
|
||||
def solve(inputstr):
|
||||
w2e = inputstr.strip().split()
|
||||
n2s = transpose(w2e)
|
||||
nw2se = transpose(mirror_v(shift(mirror_v(w2e))))
|
||||
ne2sw = transpose(shift(w2e))
|
||||
|
||||
orientations = [w2e, n2s, nw2se, ne2sw]
|
||||
orientations = orientations + [mirror_h(o) for o in orientations]
|
||||
|
||||
part1 = sum(count_xmas(o) for o in orientations)
|
||||
print(f"Part 1: {part1}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue