Copyright | (c) Eric Mertens 2017 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
http://adventofcode.com/2017/day/25
Implement a Turing Machine.
Synopsis
- data D
- main :: IO ()
- steps :: Int -> Machine -> Machine
- step :: Machine -> Machine
- updateSet :: Bool -> Int -> IntSet -> IntSet
- data Machine = Machine !IntSet !Int !(Fix Rule)
- buildProgram :: [(Char, Rule Char)] -> Char -> Fix Rule
- data Rule a = Rule (Action a) (Action a)
- data Action a = Action !Bool !Int a
Documentation
Print the solution to the task. Input file can be overridden via command-line arguments.
updateSet :: Bool -> Int -> IntSet -> IntSet Source #
When the argument is True
, insert the given number into the set,
otherwise remove it from the set.
The state of a machine: tape, cursor address, current program
buildProgram :: [(Char, Rule Char)] -> Char -> Fix Rule Source #
Transform a list of named rules into a single program.
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.
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.