60 lines
2 KiB
Text
60 lines
2 KiB
Text
Day 16 Notes
|
|
|
|
+--------+
|
|
| Part 1 |
|
|
+--------+
|
|
|
|
$ elixir day16part1.exs
|
|
28884
|
|
|
|
Thoughts:
|
|
|
|
Slightly complex input to parse this time. Most of the solution is parsing.
|
|
The actual logic: Use Enum.any?(rules) to check if a ticket satisfies any of the rules.
|
|
Filter those results by only those that are not valid.
|
|
Flat map the filtered tickets, to get a flat list of fields.
|
|
Sum the result.
|
|
|
|
|
|
+--------+
|
|
| Part 2 |
|
|
+--------+
|
|
|
|
$ elixir day16part2.exs
|
|
1001849322119
|
|
|
|
Thoughts:
|
|
|
|
More complicated as I initially thought, because most columns are valid for more than
|
|
one rule. Interestingly no column is valid for the *same* number of rules, which makes me
|
|
think this is a manifestation of some maths problem I don't know about.
|
|
|
|
Anyway, solve it by:
|
|
* Transposing the tickets into lists of "columns"
|
|
* Match each column against the rules it satisfies
|
|
* Starting with the column that only matches one rule, mark that column as solved.
|
|
* Continue for subsequent rules, removing the solved columns from the set of rules it
|
|
satisfies as we go.
|
|
|
|
I'm sure there is a more efficient way to handle this rather than the building up n lists
|
|
and then for each entry removing that from the remaining lists.
|
|
|
|
** UPDATE 17 December **
|
|
|
|
I refactored part 2, and I'm much happier with it now.
|
|
Most of the simplifications I thought of myself, but there was one change I read on the ElixirForum,
|
|
using Enum.zip to transpose the ticket rows to columns, which I wanted to use, so I committed that
|
|
change only to day16paet2-simpler-transpose.exs.
|
|
|
|
|
|
+------------------+
|
|
| Overall Thoughts |
|
|
+------------------+
|
|
|
|
Spent a bit too long on silly mistakes in this one. Think I need to consider my development
|
|
process to help avoid making errors, especially when dealing with multiple related data structures
|
|
/ representation of those data structures.
|
|
|
|
Also, I'm finding these daily puzzles a bit too distracting from work. I think after today
|
|
I'm going to relegate them to the weekend. Doing them in the evenings has too much potential
|
|
to spill over into the next day.
|