DEV Community

loading...

Discussion on: Advent of Code 2020 Solution Megathread - Day 1: Report Repair

Collapse
patryk profile image
Patryk Woziński

Hi! It was also my first time in Advent of Code.

There is my solution for the first day in Elixir: click, GitHub

Except input setup the code looks like:

  def part1() do
    numbers = Enum.map(@numbers, &String.to_integer(&1))

    [res | _] = for x <- numbers,
      y <- numbers,
      x + y == 2020,
      do: x * y

    res
  end

  def part2() do
    numbers = Enum.map(@numbers, &String.to_integer(&1))

    [res | _] = for x <- numbers,
      y <- numbers,
      z <- numbers,
      x + y + z == 2020,
      do: x * y * z

    res
  end
Enter fullscreen mode Exit fullscreen mode