1
0
Fork 0

Day 25 - AoC 2017 all done :)

This commit is contained in:
Jonathan Chan 2017-12-25 16:03:27 -08:00
parent 42ef138744
commit a0bae97745
3 changed files with 100 additions and 1 deletions

36
25.hs Normal file
View File

@ -0,0 +1,36 @@
{-# LANGUAGE BangPatterns #-}
import Data.IntMap.Strict (IntMap, findWithDefault, insert, empty)
type Tape = IntMap Int
type Step = (Tape, Int, State)
data State = State {
zeroVal :: Int,
oneVal :: Int,
zeroPos :: Int,
onePos :: Int,
zeroState :: State,
oneState :: State
}
a, b, c, d, e, f :: State
a = State 1 0 1 (-1) b e
b = State 1 0 (-1) 1 c a
c = State 1 0 (-1) 1 d c
d = State 1 0 (-1) (-1) e f
e = State 1 1 (-1) (-1) a c
f = State 1 1 (-1) 1 e a
step :: Step -> Step
step (tape, position, (State zval oval zpos opos zstate ostate)) =
case findWithDefault 0 position tape of
0 -> (insert position zval tape, position + zpos, zstate)
1 -> (insert position oval tape, position + opos, ostate)
stepN :: Int -> Step -> Step
stepN 0 s = s
stepN n s = let !nextStep = step s in stepN (n - 1) nextStep
main :: IO ()
main = do
let (tape, _, _) = stepN 12386363 (empty, 0, a)
print $ foldr (+) 0 tape

62
25.txt Normal file
View File

@ -0,0 +1,62 @@
Begin in state A.
Perform a diagnostic checksum after 12386363 steps.
In state A:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state B.
If the current value is 1:
- Write the value 0.
- Move one slot to the left.
- Continue with state E.
In state B:
If the current value is 0:
- Write the value 1.
- Move one slot to the left.
- Continue with state C.
If the current value is 1:
- Write the value 0.
- Move one slot to the right.
- Continue with state A.
In state C:
If the current value is 0:
- Write the value 1.
- Move one slot to the left.
- Continue with state D.
If the current value is 1:
- Write the value 0.
- Move one slot to the right.
- Continue with state C.
In state D:
If the current value is 0:
- Write the value 1.
- Move one slot to the left.
- Continue with state E.
If the current value is 1:
- Write the value 0.
- Move one slot to the left.
- Continue with state F.
In state E:
If the current value is 0:
- Write the value 1.
- Move one slot to the left.
- Continue with state A.
If the current value is 1:
- Write the value 1.
- Move one slot to the left.
- Continue with state C.
In state F:
If the current value is 0:
- Write the value 1.
- Move one slot to the left.
- Continue with state E.
If the current value is 1:
- Write the value 1.
- Move one slot to the right.
- Continue with state A.

View File

@ -33,7 +33,8 @@ These are the runtimes of only one trial but the variances are fairly small and
| 22 | 12.867 | 7.880 | 22 | 12.867 | 7.880
| 23 | 0.274 | | 23 | 0.274 |
| 24 | 6.887 | | 24 | 6.887 |
| 25 | 6.072 |
Problems that could use some work: 05, 22, 14, 15, 21, 17 Problems that could use some work: 05, 22, 24, 25, 14, 15, 21, 17
Problems that are good enough with optimizations: 13 Problems that are good enough with optimizations: 13