Safe HaskellNone

Day15

Description

General - Just keep the last time the number was spoken around and then look it up when you need to.

Note: For debugging I keep the list of turns a number was spoken around and I also build/keep the list of ages. Might need to optimize this for part2 (to reduce the mem/stack size).

Part 1 - Take 2020 turns and return the last number spoken.

Part 2 - Take 30000000 turns and return the last number spoken. Big surprise (or not): The implementation for part1 is slow, but ... ... not so slow that it is not returning a solution within 2 minutes.

Synopsis

Documentation

type Number = Int #

type Turn = Int #

type Spoken = Map Number [Turn] #

input :: String -> [Number] #

Read the input file.

speak :: Number -> Turn -> Spoken -> Spoken #

Speak the number (and return the record of spoken numbers).

whatToSay :: Number -> Turn -> Spoken -> Number #

What to say.

nextTurn :: Number -> Spoken -> Turn -> Turn -> [Number] #

What's the next turn?

solve :: Turn -> [Number] -> Number #

Solve the puzzle.

part1 :: [Number] -> Number #

Solve part1.

part2 :: [Number] -> Number #

Solve part2.