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

Main

Description

https://adventofcode.com/2017/day/8

Day 8 poses a problem of parsing a simple programming language, executing it, and computing simple metrics on the values stored in variables during execution.

>>> :{
:main +
  "b inc 5 if a > 1\n\
  \a inc 1 if b < 5\n\
  \c dec -10 if a >= 1\n\
  \c inc -20 if c == 10\n"
:}
1
10
Synopsis

Documentation

data C Source #

Constructors

Cinc 
Cdec 

Instances

Instances details
Show C Source # 
Instance details

Defined in Main

Methods

showsPrec :: Int -> C -> ShowS #

show :: C -> String #

showList :: [C] -> ShowS #

main :: IO () Source #

Compute solution to Day 8. Input file can be overridden with command-line arguments.

>>> :main
4163
5347

interpret Source #

Arguments

:: Map String Int

incoming registers

-> (String, C, Int, String, String, Int)

statement

-> Map String Int

outgoing registers

Given registers and a statement, compute the resulting registers.

toCompare Source #

Arguments

:: String

name

-> Int

function

-> Int 
-> Bool 

Convert the string representation of a comparison to a function.

toArith Source #

Arguments

:: C

name

-> Int

function

-> Int 
-> Int 

Convert the string representation of an arithmetic operation to a function.