2020-12-01 05:19:13 +00:00
|
|
|
Day 1 Notes
|
|
|
|
|
2020-12-01 05:36:44 +00:00
|
|
|
------
|
2020-12-01 05:19:13 +00:00
|
|
|
Part1:
|
2020-12-01 05:36:44 +00:00
|
|
|
------
|
2020-12-01 05:19:13 +00:00
|
|
|
|
|
|
|
$ elixir day1part1.exs
|
|
|
|
618 x 1402 = 866436
|
2020-12-01 05:36:44 +00:00
|
|
|
|
|
|
|
Thoughts:
|
|
|
|
|
|
|
|
Avoid iterating seen elements by consuming the list, and comparing each list element only to the remaining
|
|
|
|
elements.
|
|
|
|
|
|
|
|
------
|
|
|
|
Part2:
|
|
|
|
------
|
|
|
|
|
|
|
|
$ elixir day1part2.exs
|
|
|
|
547 x 545 x 928 = 276650720
|
|
|
|
|
|
|
|
Thoughts:
|
|
|
|
|
|
|
|
Use a comprehension over two versions of the remaining list to efficiently compare the three items.
|
|
|
|
|
2020-12-01 05:47:20 +00:00
|
|
|
Would have been simpler to use a comprehension for all 3 elements (and for the 2 elements from part 1)
|
|
|
|
rather than using recursion for the outer loop.
|
|
|
|
|
|
|
|
E.g.
|
|
|
|
|
|
|
|
for i <- list, j <- list, k <- list, do: ...
|
|
|
|
|
2020-12-01 06:59:46 +00:00
|
|
|
However, can't short-circuit comprehensions, so maybe recursion was a good choice after all 🤷♂️
|
|
|
|
|