aoc2022/18-a.hs

18 lines
560 B
Haskell

import Common
import Data.List.Split (splitOn)
parse :: String -> [Pos3]
parse = map ((\[x, y, z] -> (x, y, z)) . map read . splitOn ",") . lines
getAdjacentPos3 :: Pos3 -> [Pos3]
getAdjacentPos3 pos = map (add3 pos) pos3Permutations
pos3Permutations :: [Pos3]
pos3Permutations = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (-1, 0, 0), (0, -1, 0), (0, 0, -1)]
surfaceArea :: [Pos3] -> Pos3 -> Int
surfaceArea positions pos = (6 -) $ count (`elem` positions) $ getAdjacentPos3 pos
main = interact $
show
. (\cubes -> sum $ map (surfaceArea cubes) cubes)
. parse