aoc/01/01.exs
2020-12-02 07:11:58 -06:00

10 lines
382 B
Elixir

list = File.read!("input.txt")
|> String.split("\n")
|> Enum.map(&String.to_integer/1)
# pattern match binary tuple from list values
[{a, b} | _] = for x <- list, y <- list, x + y == 2020, do: {x, y}
IO.puts("Part 1: #{a * b}")
# same thing but with 3-ary tuple
[{a, b, c} | _] = for x <- list, y <- list, z <- list, x + y + z == 2020, do: {x, y, z}
IO.puts("Part 2: #{a * b * c}")