Merge branch 'main' of ssh://git.fedaya.net:16357/AdventOfCode/2024
This commit is contained in:
commit
2fb5ac7e8f
@ -1,3 +1,3 @@
|
|||||||
def parse(filename: str) -> list[str]:
|
def parse(filename: str) -> list[int]:
|
||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
return [line.strip() for line in f.readlines()]
|
return [line.strip() for line in f.readlines()]
|
||||||
|
21
day4/part2.py
Executable file
21
day4/part2.py
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
from common import parse
|
||||||
|
|
||||||
|
|
||||||
|
def is_x_mas(input: list[str], x: int, y: int) -> bool:
|
||||||
|
return "".join([input[y + i][x + i] for i in range(3)]) in ["MAS", "SAM"] and "".join(
|
||||||
|
[input[y + 2 - i][x + i] for i in range(3)]
|
||||||
|
) in ["MAS", "SAM"]
|
||||||
|
|
||||||
|
|
||||||
|
def solve(input: list[str]) -> str:
|
||||||
|
starts = [(x, y) for x in range(len(input[0]) - 2) for y in range(len(input) - 2)]
|
||||||
|
return len(list(filter(lambda p: is_x_mas(input, p[0], p[1]), starts)))
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print(solve(parse("input")))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
day=$1
|
day=$1
|
||||||
|
if [ ! -d day${day} ]; then
|
||||||
mkdir day${day}
|
mkdir day${day}
|
||||||
cp template/* day${day}
|
cp template/* day${day}
|
||||||
|
fi
|
||||||
curl -o day${day}/input --cookie ~/AdventOfCode/2024/cookies.txt https://adventofcode.com/2024/day/$day/input
|
curl -o day${day}/input --cookie ~/AdventOfCode/2024/cookies.txt https://adventofcode.com/2024/day/$day/input
|
||||||
|
Loading…
x
Reference in New Issue
Block a user