diff options
author | Laura Orvokki Kursula <lav@vampires.gay> | 2024-12-04 23:07:38 +0100 |
---|---|---|
committer | Laura Orvokki Kursula <lav@vampires.gay> | 2024-12-04 23:23:45 +0100 |
commit | f7b5d3a1d7fc509e105b9b58a6519fe3d50a91a8 (patch) | |
tree | 765634636d6cecd88ed5cb48d295187468770b35 | |
parent | 3a15eef7459c586b0dcb8138d1f2c3f0ff1da64f (diff) | |
download | aoc2024-f7b5d3a1d7fc509e105b9b58a6519fe3d50a91a8.tar.gz aoc2024-f7b5d3a1d7fc509e105b9b58a6519fe3d50a91a8.zip |
4-2
-rw-r--r-- | 4-2.hs | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -0,0 +1,26 @@ +import Control.Monad (ap) + +width, height :: [[a]] -> Int +height = length +width = length . head + +crop :: Int -> Int -> [[a]] -> [[a]] +crop x y = map (take 3 . drop x) . take 3 . drop y + +diag :: [[a]] -> [a] +diag xss = [ xss !! x !! x | x <- [0 .. length xss - 1] ] + +diags :: ([a] -> Bool) -> [[a]] -> Bool +diags p = all p . ((diag .) <$> [ id, map reverse ] <*>) . pure + +mas :: String -> Bool +mas = elem "MAS" . ap [ id, reverse ] . pure + +count :: [[Char]] -> Int +count xss = length . filter id $ [ diags mas (crop x y xss) + | x <- [0 .. width xss - 3] + , y <- [0 .. height xss - 3] + ] + +main :: IO () +main = getContents >>= print . count . lines |