projects
/
advent-of-code-19.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0687ede
)
A bit of tidying
author
Neil Smith
<neil.git@njae.me.uk>
Fri, 13 Dec 2019 10:12:05 +0000
(10:12 +0000)
committer
Neil Smith
<neil.git@njae.me.uk>
Fri, 13 Dec 2019 10:12:05 +0000
(10:12 +0000)
advent12/src/advent12.hs
patch
|
blob
|
history
diff --git
a/advent12/src/advent12.hs
b/advent12/src/advent12.hs
index efd693b8ba578b2b25775a1148e89e845a642d09..043e8d096ce7378bff43d3c66d23a4ff1682e835 100644
(file)
--- a/
advent12/src/advent12.hs
+++ b/
advent12/src/advent12.hs
@@
-46,7
+46,7
@@
main = do
print $ part2 planets
part1 :: Planets (V3 Integer) -> Integer
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
part2 :: Planets (V3 Integer) -> Integer
part2 planets = period
@@
-56,16
+56,19
@@
part2 planets = period
enplanet :: (NVec a) => [a] -> Planets a
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 :: 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
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]
unzipVec :: V3 Integer -> [V1 Integer]
unzipVec (V3 x y z) = [V1 x, V1 y, V1 z]