1
0
Fork 0
advent-of-code-2024/src/Day4/Part2.idr

33 lines
739 B
Idris

module Day4.Part2
import Data.String
import Data.Vect
import Day4.Part1
import Utils
%default total
--- DATA
checkMS : {h, w : _} -> Board h w -> Pos h w -> Bool
checkMS board pos =
let Just [ul, ur, dl, dr] =
map (map (`index` board))
$ traverse {t=Vect _} (`moveDir` pos) [UL, UR, DL, DR]
| Nothing => False
in ((ul == 'M' && dr == 'S') || (ul == 'S' && dr == 'M')) &&
((ur == 'M' && dl == 'S') || (ur == 'S' && dl == 'M'))
countMAS : {h, w : _} -> Board h w -> Nat
countMAS board = count (checkMS board) $ findChar board 'A'
--- SOLUTION
export
solution : String -> Maybe Nat
solution inp =
let Just (_ ** _ ** board) = parseInput inp
| Nothing => Nothing
in Just $ countMAS board