From: Neil Smith <neil.git@njae.me.uk>
Date: Wed, 20 Dec 2017 17:21:43 +0000 (+0000)
Subject: Tweaking
X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=4239d37fe8afca7f921378e266e67dafc03923e4;p=advent-of-code-17.git

Tweaking
---

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
diff --git a/src/advent20/advent20.ipynb b/src/advent20/advent20.ipynb
index c73e459..20f0074 100644
--- a/src/advent20/advent20.ipynb
+++ b/src/advent20/advent20.ipynb
@@ -948,13 +948,13 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 123,
+   "execution_count": 135,
    "metadata": {},
    "outputs": [
     {
      "data": {
       "text/plain": [
-       "448"
+       "570"
       ]
      },
      "metadata": {},
@@ -962,7 +962,26 @@
     }
    ],
    "source": [
-    "part2 500 particles"
+    "part2 35 particles"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 137,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[(10,1000),(11,979),(12,979),(13,973),(14,955),(15,932),(16,921),(17,906),(18,874),(19,858),(20,831),(21,821),(22,809),(23,795),(24,791),(25,771),(26,752),(27,723),(28,703),(29,669),(30,648),(31,634),(32,622),(33,617),(34,589),(35,570),(36,542),(37,522),(38,494),(39,481),(40,448),(41,448),(42,448),(43,448),(44,448),(45,448)]"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "[(n, part2 n particles) | n <- [10..45]]"
    ]
   },
   {