@@ -261,20 +261,17 @@ def part1(input: String): Long =
261
261
## Part 2
262
262
263
263
Part 2 asks how many button presses are required for a particular output
264
- module "rv " to receive a high pulse.
264
+ module "rx " to receive a high pulse.
265
265
266
266
This can crudely be solved by just running the Elves' state machine
267
267
until you find such a pulse:
268
268
269
269
``` scala
270
270
Iterator
271
271
.iterate(MachineFSM (machine))(_.nextState)
272
- .find: state =>
273
- state.queue.headOption match
274
- case Some (Pulse (_, " rv" , true )) => true
275
- case _ => false
276
- .get
277
- .presses
272
+ .findMap: state =>
273
+ state.queue.headOption.collect:
274
+ case Pulse (_, " rx" , false ) => state.presses
278
275
```
279
276
280
277
Knowing the Advent of Code, this will not complete in any reasonable
@@ -285,7 +282,7 @@ The state machine also does not obviously lend itself to a mathematical
285
282
reduction, at least not within the available time constraints.
286
283
287
284
Instead, we have to look at the actual input text itself. Analyzing the
288
- structure of the machine, it turns out that the "rv " module is fed by a
285
+ structure of the machine, it turns out that the "rx " module is fed by a
289
286
conjunction module which is itself fed by four completely independent
290
287
subgraphs. This terminal conjunction will emit a high pulse when it
291
288
receives a high pulse from each of the subgraphs.
@@ -332,10 +329,10 @@ object Problem2FSM:
332
329
#### Subgraphs
333
330
334
331
The terminal module is a module that doesn't serve as an input to
335
- any other module. We could hardcode "rv ", but this is more general.
332
+ any other module. We could hardcode "rx ", but this is more general.
336
333
The output modules of the independent subgraphs are then all the
337
334
inputs to the sole input to this terminal conjunction:
338
- ("a", "b", "c", "d") -> "penultimate" -> "rv ".
335
+ ("a", "b", "c", "d") -> "penultimate" -> "rx ".
339
336
340
337
``` scala
341
338
private def subgraphs (machine : Machine ): Set [ModuleName ] =
0 commit comments