This commit is contained in:
2023-12-30 22:33:03 +01:00
parent c568ce2677
commit 262ad03e46
5 changed files with 121 additions and 0 deletions

24
day24/Commons.hs Normal file
View File

@@ -0,0 +1,24 @@
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