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