AdventOfCode/2020/elixir/day1
Adam Millerchip 39c28b5897 Move 2020 elixir solutions to 2020/elixir in prep for zig 2022-08-11 16:22:22 +09:00
..
README Move 2020 elixir solutions to 2020/elixir in prep for zig 2022-08-11 16:22:22 +09:00
day1part1.exs Move 2020 elixir solutions to 2020/elixir in prep for zig 2022-08-11 16:22:22 +09:00
day1part2.exs Move 2020 elixir solutions to 2020/elixir in prep for zig 2022-08-11 16:22:22 +09:00
day1refactored.exs Move 2020 elixir solutions to 2020/elixir in prep for zig 2022-08-11 16:22:22 +09:00
input Move 2020 elixir solutions to 2020/elixir in prep for zig 2022-08-11 16:22:22 +09:00

README

Day 1 Notes

------
Part1:
------

$ elixir day1part1.exs
618 x 1402 = 866436

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.

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: ...

However, can't short-circuit comprehensions, so maybe recursion was a good choice after all 🤷‍♂️

Tried it out, and turned out that while it doesn't short-circuit, it's still pretty quick. So I added
day1refactored.exs with the simpler implementation.

$ elixir day1refactored.exs
Part1: 618 x 1402 = 866436
Part2: 928 x 547 x 545 = 276650720