Files
advent-of-code-2023/day24/Commons.hs
2024-01-01 12:28:01 +01:00

25 lines
868 B
Haskell

module Commons where
import GHC.IO.Handle (isEOF)
import Data.List.Utils (split)
data Hailstone = Hailstone { x :: Int, y :: Int, z :: Int, vx :: Int, vy :: Int, vz :: Int } deriving Show
parseHail :: String -> String -> Hailstone
parseHail pos speed = let (rX: rY: rZ: _) = split ", " pos
(rVx: rVy: rVz: _) = split ", " speed
in Hailstone { x = read rX, y = read rY, z = read rZ,
vx = read rVx, vy = read rVy, vz = read rVz }
parse :: IO [Hailstone]
parse = do done <- isEOF
if done
then return []
else do line <- getLine
let (rawPos: rawSpeed: _) = split " @ " line
let hail = parseHail rawPos rawSpeed
otherHail <- parse
return $ hail: otherHail