Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Day 01

lib/day_01.livemd

Day 01

Notes

Take and parse the input

input = Kino.Input.textarea("Problem Input:")
input_arr =
  input
  |> Kino.Input.read()
  |> String.split("\n", trim: true)
  |> Enum.map(&String.to_integer/1)
[178, 205, 212, 210, 215, 220, 223, 224, 230, 232, 235, 225, 226, 227, 238, 248, 249, 251, 252, 261,
 273, 283, 284, 286, 296, 297, 303, 317, 320, 333, 370, 339, 342, 345, 325, 323, 334, 325, 326, 327,
 333, 329, 337, 340, 363, 353, 341, 344, 345, 364, ...]

Problem 01

input_arr
|> Enum.chunk_every(2, 1, :discard)
|> Enum.count(fn [first, last] -> last > first end)
1676

Problem 02

input_arr
|> Enum.chunk_every(3, 1, :discard)
|> Enum.map(&Enum.sum/1)
|> Enum.chunk_every(2, 1, :discard)
|> Enum.count(fn [first, last] -> last > first end)
1706