Day 4
This commit is contained in:
parent
341a64b794
commit
8008efa1d1
1 changed files with 18 additions and 0 deletions
18
4.jl
Normal file
18
4.jl
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
const matchEitherDir(a) = fn(b) = all(a .== b) || all(reverse(a) .== b)
|
||||
|
||||
const d = [ collect(line) for line in readlines("input/4") ]
|
||||
const size = length(d)
|
||||
|
||||
partOne, partTwo = 0, 0
|
||||
|
||||
for y in 1:size
|
||||
for x in 1:size
|
||||
grid(dirs, range) = ( ( try d[y+i*u][x+i*v] catch end for i in range ) for (u,v) in dirs )
|
||||
global partOne += count(matchEitherDir(collect("XMAS")), grid([ (0, 1), (1, 0), (1, 1), (-1, 1) ], 0:3))
|
||||
global partTwo += all(matchEitherDir(collect("MAS")), grid([ (-1, 1), (1, 1) ], -1:1))
|
||||
end
|
||||
end
|
||||
|
||||
@show partOne, partTwo
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue