sln_2017_20
Copyright(c) Eric Mertens 2017
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Main

Description

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

Documentation

main :: IO () Source #

Print the solutions. Input file can be overridden via command-line arguments.

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.

minimumIndexOn Source #

Arguments

:: Ord b 
=> (a -> b)

projection

-> [a] 
-> Int 

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.

zeros Source #

Arguments

:: V3 Double

polynomial coefficients

-> [Double]

list of values when polynomial evaluates to 0

Given coefficients V3 a b c compute the values of x 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.

toEvents :: [Particle] -> [[V2 Int]] Source #

Compute the collisions that will happen between a list of particles grouped by the time-step that they happen at.

runGeneration Source #

Arguments

:: IntSet

previously collided particles

-> [V2 Int]

possible collisions this time-step

-> IntSet

dead particles after this time-step