@@ -5,10 +5,10 @@ import Dict exposing (Dict)
5
5
import List.Extra
6
6
7
7
8
- main : Program Never ( Output , Output ) Never
8
+ main : Program () ( Output , Output ) Never
9
9
main =
10
10
Advent . program
11
- { input = input
11
+ { input = input_
12
12
, parse1 = parse
13
13
, parse2 = parse
14
14
, compute1 = compute1
@@ -81,11 +81,13 @@ run : Tape -> Input -> Int
81
81
run tape { state, stepsToChecksum, rules, position } =
82
82
if stepsToChecksum == 0 then
83
83
countOnes tape
84
+
84
85
else
85
86
let
86
87
_ =
87
- if stepsToChecksum % 100000 == 0 then
88
- Debug . log ( toString stepsToChecksum) ( state, position )
88
+ if modBy 100000 stepsToChecksum == 0 then
89
+ Debug . log ( Debug . toString stepsToChecksum) ( state, position )
90
+
89
91
else
90
92
( state, position )
91
93
@@ -107,7 +109,7 @@ run tape { state, stepsToChecksum, rules, position } =
107
109
rule. if1
108
110
109
111
_ ->
110
- Debug . crash " value other than 0/1 ????"
112
+ Debug . todo " value other than 0/1 ????"
111
113
112
114
newPosition =
113
115
move decision. moveTo position
@@ -118,12 +120,12 @@ run tape { state, stepsToChecksum, rules, position } =
118
120
newTape =
119
121
tape |> Dict . insert position decision. valueToWrite
120
122
in
121
- run newTape
122
- { state = newState
123
- , stepsToChecksum = stepsToChecksum - 1
124
- , rules = rules
125
- , position = newPosition
126
- }
123
+ run newTape
124
+ { state = newState
125
+ , stepsToChecksum = stepsToChecksum - 1
126
+ , rules = rules
127
+ , position = newPosition
128
+ }
127
129
128
130
129
131
move : Direction -> Int -> Int
@@ -173,39 +175,41 @@ In state B:
173
175
- Write the value 1.
174
176
- Move one slot to the right.
175
177
- Continue with state A."""
176
- { state = " A"
177
- , stepsToChecksum = 6
178
- , position = 0
179
- , rules =
180
- [ ( " A"
181
- , { if0 =
182
- { valueToWrite = 1
183
- , moveTo = Right
184
- , nextState = " B"
185
- }
186
- , if1 =
187
- { valueToWrite = 0
188
- , moveTo = Left
189
- , nextState = " B"
190
- }
191
- }
192
- )
193
- , ( " B"
194
- , { if0 =
195
- { valueToWrite = 1
196
- , moveTo = Left
197
- , nextState = " A"
178
+ ( Just
179
+ { state = " A"
180
+ , stepsToChecksum = 6
181
+ , position = 0
182
+ , rules =
183
+ [ ( " A"
184
+ , { if0 =
185
+ { valueToWrite = 1
186
+ , moveTo = Right
187
+ , nextState = " B"
188
+ }
189
+ , if1 =
190
+ { valueToWrite = 0
191
+ , moveTo = Left
192
+ , nextState = " B"
193
+ }
198
194
}
199
- , if1 =
200
- { valueToWrite = 1
201
- , moveTo = Right
202
- , nextState = " A"
195
+ )
196
+ , ( " B"
197
+ , { if0 =
198
+ { valueToWrite = 1
199
+ , moveTo = Left
200
+ , nextState = " A"
201
+ }
202
+ , if1 =
203
+ { valueToWrite = 1
204
+ , moveTo = Right
205
+ , nextState = " A"
206
+ }
203
207
}
204
- }
205
- )
206
- ]
207
- |> Dict . fromList
208
- }
208
+ )
209
+ ]
210
+ |> Dict . fromList
211
+ }
212
+ )
209
213
3
210
214
]
211
215
@@ -226,7 +230,7 @@ parse input =
226
230
}
227
231
228
232
_ ->
229
- Debug . crash " wrong input!"
233
+ Debug . todo " wrong input!"
230
234
231
235
232
236
parseState : String -> State
@@ -246,7 +250,7 @@ parseChecksum string =
246
250
|> List . reverse
247
251
|> List . drop 1
248
252
|> List . head
249
- |> Maybe . map Advent . toInt
253
+ |> Maybe . map Advent . unsafeToInt
250
254
|> Advent . unsafeMaybe
251
255
252
256
@@ -283,7 +287,7 @@ parseRule ruleLines =
283
287
)
284
288
285
289
_ ->
286
- Debug . crash " wrong input??"
290
+ Debug . todo " wrong input??"
287
291
288
292
289
293
parseMoveTo : String -> Direction
@@ -307,7 +311,7 @@ parseDirection string =
307
311
Right
308
312
309
313
_ ->
310
- Debug . crash " wrong input!"
314
+ Debug . todo " wrong input!"
311
315
312
316
313
317
parseValueToWrite : String -> Int
@@ -317,12 +321,12 @@ parseValueToWrite string =
317
321
|> String . words
318
322
|> List . reverse
319
323
|> List . head
320
- |> Maybe . map Advent . toInt
324
+ |> Maybe . map Advent . unsafeToInt
321
325
|> Advent . unsafeMaybe
322
326
323
327
324
- input : String
325
- input =
328
+ input_ : String
329
+ input_ =
326
330
""" Begin in state A.
327
331
Perform a diagnostic checksum after 12523873 steps.
328
332
0 commit comments