Safe HaskellNone

Day23

Description

General - Read careful. There is nothing difficult about this. if you follow the instructions and implement the actions correctly you will find/get the solution.

One small trick/simplification. The position of current does not matter. And that means we can *just* reorder the list in/with the last action of every move/cycle to make current the first element of the list.

Part 1 - So far so good.

Part 2 - Big surprise: The (initial) list based solution does not work. Way to slow. To get a grip on this I ...

  • ... introduced a CircularList type
  • ... that was (initially) using a list (means we get no performance improvements, but we get a nice interface)
  • ... and then I experimented with various data-structures to improve the performance

There are various day23p2-* branches that you can take a look at to see/understand the options I looked at. At the end I went with a vector based implementation (that is still very slow).

Synopsis

Documentation

type Moves = Int #

type Pickup = Int #

data State #

The State to maintain between moves.

Constructors

State Moves CircularList [Pickup] 

Instances

Instances details
Eq State # 
Instance details

Defined in Day23

Methods

(==) :: State -> State -> Bool

(/=) :: State -> State -> Bool

Show State # 
Instance details

Defined in Day23

Methods

showsPrec :: Int -> State -> ShowS

show :: State -> String

showList :: [State] -> ShowS

input :: String -> State #

Read the input and return the initial state.

removeCups :: State -> State #

As part of a move: Remove 3 cups (and put them into pickup).

selectDestination :: State -> State #

As part of a move: Select the next destination/current.

placePickupCups :: State -> State #

As part of a move: Place the cups from pickup.

newCurrentCup :: State -> State #

As part of a move: Determine the new current cup.

actions :: State -> State #

All the actions of a move.

executeMoves :: State -> State #

Execute moves (until there are no more moves to make).

collect :: Int -> CircularList -> [Int] #

Collect the cups after cup label

ints2Int :: [Int] -> Int #

Turn a list of ints into an int.

part1 :: State -> Int #

Solve part1.

collect' :: Int -> CircularList -> (Int, Int) #

Collect values of the 2 ups after cup label

part2 :: State -> Int #

Solve part2.