X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=src%2Fadvent20%2Fadvent20.hs;fp=src%2Fadvent20%2Fadvent20.hs;h=a7656a458da6e86ae9014f64df9e239f4741c365;hb=4239d37fe8afca7f921378e266e67dafc03923e4;hp=5aac088be3b995678a2f72e9bf43536be7ad1869;hpb=3a37ea61c6b83fc84fcf3369c77c399a91fd9759;p=advent-of-code-17.git diff --git a/src/advent20/advent20.hs b/src/advent20/advent20.hs index 5aac088..a7656a4 100644 --- a/src/advent20/advent20.hs +++ b/src/advent20/advent20.hs @@ -13,7 +13,6 @@ import qualified Text.Megaparsec.Lexer as L import Text.Megaparsec.Text (Parser) import qualified Control.Applicative as CA --- import Data.Vector ((!), (//)) import qualified Data.Vector as V import Data.List @@ -61,7 +60,7 @@ simulateC t particles = simulateC (t - 1) (map step particles') step :: Particle -> Particle step particle = particle {position = p', velocity = v'} where pv' = V.zipWith3 updatePV (position particle) (velocity particle) (acceleration particle) - !(p', v') = V.unzip pv' + (p', v') = V.unzip pv' updatePV p v a = (p + v + a, v + a) @@ -69,11 +68,11 @@ step particle = particle {position = p', velocity = v'} quiescent :: Particle -> Bool quiescent particle = and qDimensions where qDimensions = V.zipWith3 sameSigns (position particle) (velocity particle) (acceleration particle) - sameSigns !p !v !a = if a == 0 && v == 0 - then True - else if a == 0 - then signum p == signum v - else signum p == signum v && signum v == signum a + sameSigns p v a = if a == 0 && v == 0 + then True + else if a == 0 + then signum p == signum v + else signum p == signum v && signum v == signum a withMinX particles = minX `elemIndices` absXs @@ -84,7 +83,6 @@ pAbsX :: Particle -> Integer pAbsX particle = V.foldl1' (+) $ V.map abs (position particle) - removeColliders particles = particles' where positions = map position particles duplicatePositions = S.fromList $ concat $ filter (\g -> length g > 1) $ group $ sort positions