From 03695636b2be7faa5d3f16912eb4aefab2418ec3 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 13 Dec 2019 10:12:05 +0000 Subject: [PATCH] A bit of tidying --- advent12/src/advent12.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/advent12/src/advent12.hs b/advent12/src/advent12.hs index efd693b..043e8d0 100644 --- a/advent12/src/advent12.hs +++ b/advent12/src/advent12.hs @@ -46,7 +46,7 @@ main = do print $ part2 planets part1 :: Planets (V3 Integer) -> Integer -part1 planets = systemEnergy $ head $ drop 1000 $ simulate planets +part1 = systemEnergy . head . drop 1000 . simulate part2 :: Planets (V3 Integer) -> Integer part2 planets = period @@ -56,16 +56,19 @@ part2 planets = period enplanet :: (NVec a) => [a] -> Planets a -enplanet = V.fromList . map (\p -> Planet {_pos = p, _vel = nvZero} ) +enplanet = V.fromList . map mkPlanet + +mkPlanet :: (NVec a) => a -> Planet a +mkPlanet p = Planet {_pos = p, _vel = nvZero} unzipPlanets :: V.Vector (Planet (V3 Integer)) -> [V.Vector (Planet (V1 Integer))] -unzipPlanets planets = dimensionSlice $ V.map unzipPlanet planets +unzipPlanets = dimensionSlice . V.map unzipPlanet unzipPlanet :: Planet (V3 Integer) -> [Planet (V1 Integer)] unzipPlanet planet = map mkPlanet posVecs where posVecs = unzipVec $ _pos planet - mkPlanet p = Planet {_pos = p, _vel = nvZero} + unzipVec :: V3 Integer -> [V1 Integer] unzipVec (V3 x y z) = [V1 x, V1 y, V1 z] -- 2.34.1