aboutsummaryrefslogtreecommitdiff
path: root/aoc-2020-gleam/src/days/day01.gleam
blob: 1616cab69bcb3ce359c9ef03c60139690455d65a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gleam/io
import gleam/int
import gleam/list
import ext/resultx as resx
import util/input_util

fn solve(numbers: List(Int), n n: Int) -> Int {
  numbers
  |> list.combinations(by: n)
  |> list.find(one_that: fn(p) { int.sum(p) == 2020 })
  |> resx.assert_unwrap
  |> int.product
}

fn part1(numbers: List(Int)) -> Int {
  solve(numbers, n: 2)
}

fn part2(numbers: List(Int)) -> Int {
  solve(numbers, n: 3)
}

pub fn main() -> Nil {
  let test = input_util.read_numbers("test01")
  let assert 514_579 = part1(test)
  let assert 241_861_950 = part2(test)

  let input = input_util.read_numbers("day01")
  io.debug(part1(input))
  io.debug(part2(input))

  Nil
}