Copyright | (c) Eric Mertens 2017 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
http://adventofcode.com/2017/day/20
Day 20 has us implement a simple particle motion simulator.
Instead of implementing some detection for a stable state I just run this program and wait a few moments for things to stabilize before I kill it. I print incremental output so I can see how quickly things seem to settle.
Synopsis
- main :: IO ()
- type Particle = V3 (V3 Double)
- part1 :: [Particle] -> Int
- part2 :: [Particle] -> Int
- stepParticle :: Particle -> Particle
- minimumIndexOn :: Ord b => (a -> b) -> [a] -> Int
- collide :: V3 (V3 Double) -> V3 (V3 Double) -> Maybe Double
- toPoly :: V3 Double -> V3 Double
- zeros :: V3 Double -> [Double]
- toEvents :: [Particle] -> [[V2 Int]]
- process :: [[V2 Int]] -> IntSet
- runGeneration :: IntSet -> [V2 Int] -> IntSet
Documentation
type Particle = V3 (V3 Double) Source #
Characterize a particle by list of derivatives. The first vector is is the position of the particle. Each of the following vectors is an increasingly higher order derivative of the position.
part1 :: [Particle] -> Int Source #
Compute the infinite list of indexes of the particles that are nearest to the origin while iterating the system one time step at a time.
stepParticle :: Particle -> Particle Source #
Compute the index of the list element with the minimum projection.
>>>
minimumIndexOn negate [3, -10, 5, -9]
2
toPoly :: V3 Double -> V3 Double Source #
Compute coefficients of the polynomial corresponding to a triple of the particle's acceleration, velocity, and position.
Given coefficients
compute the values of V3
a b cx
such that a*x^2 + b*x + c = 0
. When all coefficients are
0
we just return 0
as this is enough for our purposes.