@@ -2002,18 +2002,24 @@ day20a = V.minIndex . V.fromList -- hijacking minIndex from Vector
2002
2002
. iterate (map step)
2003
2003
```
2004
2004
2005
- However, we could also be sneaky and just find the "maximum" normed initial
2006
- vector, which is correct in the case where all of our initial accelerations are
2007
- differently normed, and sometimes correct in the case where we have duplicated
2008
- accelerations.
2005
+ However, we are really just looking for the asymptotic behavior. In the long
2006
+ run, the distance is dominated by the ` |a| t^2 ` term, so we really just need
2007
+ to look for the particle with the highest normed initial acceleration.
2009
2008
2010
2009
``` haskell
2011
2010
day20a :: System -> Int
2012
2011
day20a = V. minIndex . V. fromList
2013
- . (map . fmap ) norm
2012
+ . (map . fmap ) norm-- [Particle Point] -> [Particle Int]
2014
2013
. parse
2015
2014
```
2016
2015
2016
+ The ` Ord ` instance of ` Particle Int ` is such that it sorts first by the ` _pAcc `
2017
+ field, then the ` _pVel ` field, then the ` _pPos ` field. So it'll find first the
2018
+ highest normed acceleration, and break ties using the highest normed velocity.
2019
+ However, this tie breaking isn't actually sound -- there are situations where
2020
+ this won't be true. However, there were no ties in my data set so this method
2021
+ was ok :)
2022
+
2017
2023
For part 2, we can define a function that takes out all "duplicated" points,
2018
2024
using a frequency map and filtering for frequencies greater than 1:
2019
2025
@@ -2058,14 +2064,14 @@ parse :: String -> System
2058
2064
parse = map parseLine . lines
2059
2065
where
2060
2066
parseLine :: String -> Particle Point
2061
- parseLine (map (read . filter numChar ). splitOn" ," -> [pX,pY,pZ,vX,vY,vZ,aX,aY,aZ])
2067
+ parseLine (map (read . filter num ). splitOn" ," -> [pX,pY,pZ,vX,vY,vZ,aX,aY,aZ])
2062
2068
= P { _pAcc = L. V3 aX aY aZ
2063
2069
, _pVel = L. V3 vX vY vZ
2064
2070
, _pPos = L. V3 pX pY pZ
2065
2071
}
2066
2072
parseLine _ = error " No parse"
2067
- numChar :: Char -> Bool
2068
- numChar c = isDigit c || c == ' -'
2073
+ num :: Char -> Bool
2074
+ num c = isDigit c || c == ' -'
2069
2075
```
2070
2076
2071
2077
### Day 20 Benchmarks
0 commit comments