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

Main

Description

http://adventofcode.com/2017/day/25

Implement a Turing Machine.

Synopsis

Documentation

data D Source #

Constructors

Dleft 
Dright 

Instances

Instances details
Show D Source # 
Instance details

Defined in Main

Methods

showsPrec :: Int -> D -> ShowS #

show :: D -> String #

showList :: [D] -> ShowS #

main :: IO () Source #

Print the solution to the task. Input file can be overridden via command-line arguments.

steps Source #

Arguments

:: Int

iterations

-> Machine 
-> Machine 

Step a machine multiple iterations.

step :: Machine -> Machine Source #

Advance the tape machine a single step.

updateSet :: Bool -> Int -> IntSet -> IntSet Source #

When the argument is True, insert the given number into the set, otherwise remove it from the set.

data Machine Source #

The state of a machine: tape, cursor address, current program

Constructors

Machine !IntSet !Int !(Fix Rule) 

buildProgram :: [(Char, Rule Char)] -> Char -> Fix Rule Source #

Transform a list of named rules into a single program.

data Rule a Source #

A rule defines a single state. The first action is used when the current value of the tape is 0, The second action is used when the current value of the tape is 1. Actions are parameterized by the type of program to jump to.

Constructors

Rule (Action a) (Action a) 

Instances

Instances details
Functor Rule Source # 
Instance details

Defined in Main

Methods

fmap :: (a -> b) -> Rule a -> Rule b #

(<$) :: a -> Rule b -> Rule a #

Show a => Show (Rule a) Source # 
Instance details

Defined in Main

Methods

showsPrec :: Int -> Rule a -> ShowS #

show :: Rule a -> String #

showList :: [Rule a] -> ShowS #

data Action a Source #

An update action for a rule containing: the new tape value, an offset to the cursor, and the next program state. Actions are parameterized by the type of program to jump to.

Constructors

Action !Bool !Int a 

Instances

Instances details
Functor Action Source # 
Instance details

Defined in Main

Methods

fmap :: (a -> b) -> Action a -> Action b #

(<$) :: a -> Action b -> Action a #

Show a => Show (Action a) Source # 
Instance details

Defined in Main

Methods

showsPrec :: Int -> Action a -> ShowS #

show :: Action a -> String #

showList :: [Action a] -> ShowS #