Skip to content

Commit

Permalink
[2024/4] use shorter dirs, convert via Vec2(dir_) instead of dir_.as_…
Browse files Browse the repository at this point in the history
…vec2()
  • Loading branch information
StarlitGhost committed Dec 4, 2024
1 parent e1f4036 commit ed6b350
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions 2024/4/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,20 @@
from GhostyUtils.vec2 import Dir, Vec2


xmas_dirs = [
Dir.EAST,
Dir.SOUTH_EAST,
Dir.SOUTH,
Dir.SOUTH_WEST,
Dir.WEST,
Dir.NORTH_WEST,
Dir.NORTH,
Dir.NORTH_EAST,
]


def search_xmas(grid: Grid, pos: Vec2) -> int:
xmas_count = 0
for dir_ in xmas_dirs:
word = [grid[pos + dir_.as_vec2() * i]
for i in range(4) if grid.in_bounds(pos + dir_.as_vec2() * i)]
for dir_ in [Dir.E, Dir.SE, Dir.S, Dir.SW, Dir.W, Dir.NW, Dir.N, Dir.NE]:
word = [grid[pos + Vec2(dir_) * i]
for i in range(4) if grid.in_bounds(pos + Vec2(dir_) * i)]
if word == list('XMAS'):
xmas_count += 1
# print(pos, dir_, word)
return xmas_count


def search_masx(grid: Grid, pos: Vec2) -> int:
one = sorted([grid[pos + Dir.NORTH_EAST], grid[pos + Dir.SOUTH_WEST]])
two = sorted([grid[pos + Dir.NORTH_WEST], grid[pos + Dir.SOUTH_EAST]])
one = sorted([grid[pos + Dir.NE], grid[pos + Dir.SW]])
two = sorted([grid[pos + Dir.NW], grid[pos + Dir.SE]])
if one == two == list('MS'):
return 1
return 0
Expand Down

0 comments on commit ed6b350

Please sign in to comment.