Safe HaskellNone

Day12

Description

General - Another "execute instructions" problem. If there is a finite set of instructions you can iterate/fold over the instructions to produce the result. If there are jumps and loops and the end of the program is determined by another condition you probably need to go with a recursion.

Part 1 - This time around we can build a list of instructions. And can just fold the instructions into a/the result. The fold will start with a position of (0, 0) and when it is done we just need to calc the manhatten distance from the final position.

Part 2 - Almost the same as part 1, but ... taking the waypoint logic into consideration.

Synopsis

Documentation

type Argument = Int #

type Position = (Int, Int) #

data Direction #

All of the directions.

Constructors

North 
South 
East 
West 

Instances

Instances details
Eq Direction # 
Instance details

Defined in Day12

Methods

(==) :: Direction -> Direction -> Bool

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

Show Direction # 
Instance details

Defined in Day12

Methods

showsPrec :: Int -> Direction -> ShowS

show :: Direction -> String

showList :: [Direction] -> ShowS

type Waypoint = (Int, Int) #

data Operation #

All of the operations.

Instances

Instances details
Eq Operation # 
Instance details

Defined in Day12

Methods

(==) :: Operation -> Operation -> Bool

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

Show Operation # 
Instance details

Defined in Day12

Methods

showsPrec :: Int -> Operation -> ShowS

show :: Operation -> String

showList :: [Operation] -> ShowS

data Instruction #

The instruction.

Instances

Instances details
Eq Instruction # 
Instance details

Defined in Day12

Methods

(==) :: Instruction -> Instruction -> Bool

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

Show Instruction # 
Instance details

Defined in Day12

Methods

showsPrec :: Int -> Instruction -> ShowS

show :: Instruction -> String

showList :: [Instruction] -> ShowS

makeOp :: Char -> Operation #

Make an operation.

input :: String -> [Instruction] #

Read the input file.

manhatten :: Position -> Position -> Int #

Calculate the manhatten distance.

execute :: State -> Instruction -> State #

Execute the instruction and return the next state (part1).

part1 :: [Instruction] -> Int #

Solve part1.

execute' :: State' -> Instruction -> State' #

Execute the instruction and return the next state (part2).

part2 :: [Instruction] -> Int #

Solve part2.