Today’s puzzle is cute:
To start, each part is rated in each of four categories:
* `x`: E*x*tremely cool looking
* `m`: *M*usical (it makes a noise when you hit it)
* `a`: *A*erodynamic
* `s`: *S*hiny
Kind of embarrassed how I didn’t notice what the categories “spelled out” at first.
I solved it in a manner similar to Day 5: interval splitting. Only this time, you have 4 simultaneous intervals to keep in mind, which makes it slightly more challenging. Given a location and a group of intervals (one for each category), examine the location’s rule. If none of its criteria apply, move the group to the default and re-enqueue it. If a criterion applies, then either reassign the intervals to the new location (if they all satisfy the criterion) or enqueue two new groups, one for the subinterval that satisfies the criterion (which has a new location), and one for the one that doesn’t (which is still in the same location).
Using the original example:
- Start at
in
with intervals (1,4000),(1,4000),(1,4000),(1,4000). - The rule
s < 1351
applies, so enqueue two new groups by splutting this one: the first group is atpx
, with intervals (1,4000),(1,4000),(1,4000),(1,1350); the other remains atin
with intervals (1,4000),(1,4000),(1,4000),(1351,4000).
…and so forth. When a group visits A
, add the group’s number of intervals to the running total; when a group visits R
, discard the group altogether.