Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4ed88b8

Browse files
committed
clarified day 20
1 parent df1048b commit 4ed88b8

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

‎reflections.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,18 +2002,24 @@ day20a = V.minIndex . V.fromList -- hijacking minIndex from Vector
20022002
. iterate (map step)
20032003
```
20042004

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.
20092008

20102009
```haskell
20112010
day20a :: System -> Int
20122011
day20a = V.minIndex . V.fromList
2013-
. (map . fmap) norm
2012+
. (map . fmap) norm-- [Particle Point] -> [Particle Int]
20142013
. parse
20152014
```
20162015

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+
20172023
For part 2, we can define a function that takes out all "duplicated" points,
20182024
using a frequency map and filtering for frequencies greater than 1:
20192025

@@ -2058,14 +2064,14 @@ parse :: String -> System
20582064
parse = map parseLine . lines
20592065
where
20602066
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])
20622068
= P { _pAcc = L.V3 aX aY aZ
20632069
, _pVel = L.V3 vX vY vZ
20642070
, _pPos = L.V3 pX pY pZ
20652071
}
20662072
parseLine _ = error "No parse"
2067-
numChar :: Char -> Bool
2068-
numChar c = isDigit c || c == '-'
2073+
num :: Char -> Bool
2074+
num c = isDigit c || c == '-'
20692075
```
20702076

20712077
### Day 20 Benchmarks

‎src/AOC2017/Day20.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ parse :: String -> System
5454
parse = map parseLine . lines
5555
where
5656
parseLine :: String -> Particle Point
57-
parseLine (map(read.filter numChar).splitOn","->[pX,pY,pZ,vX,vY,vZ,aX,aY,aZ])
57+
parseLine (map(read.filter num).splitOn","->[pX,pY,pZ,vX,vY,vZ,aX,aY,aZ])
5858
= P { _pAcc = L.V3 aX aY aZ
5959
, _pVel = L.V3 vX vY vZ
6060
, _pPos = L.V3 pX pY pZ
6161
}
6262
parseLine _ = error "No parse"
63-
numChar :: Char -> Bool
64-
numChar c = isDigit c || c == '-'
63+
num :: Char -> Bool
64+
num c = isDigit c || c == '-'

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /