modified get_input.sh to be able to get input without recreating the folder. Day4 completed
This commit is contained in:
parent
2a82cd35e9
commit
0df3ad93e8
@ -1,3 +1,3 @@
|
||||
def parse(filename: str) -> list[str]:
|
||||
def parse(filename: str) -> list[int]:
|
||||
with open(filename) as f:
|
||||
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
|
||||
day=$1
|
||||
mkdir day${day}
|
||||
cp template/* day${day}
|
||||
if [ ! -d day${day} ]; then
|
||||
mkdir day${day}
|
||||
cp template/* day${day}
|
||||
fi
|
||||
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