# Day 02 ```elixir Mix.install([:kino_aoc]) ``` ## Section ```elixir {:ok, puzzle_input} = KinoAOC.download_puzzle("2024", "2", System.fetch_env!("LB_ADVENT_OF_CODE_SESSION")) ``` ```elixir inputs = puzzle_input |> String.split("\n", trim: true) |> Enum.map(fn row -> row |> String.split(" ", trim: true) |> Enum.map(&String.to_integer/1) end) ``` ```elixir defmodule Day02 do def correct?([a, b | _] = input) do cmp = if a > b, do: &>/2, else: & abs(c - d) in 1..3 and cmp.(c, d) end input |> Enum.chunk_every(2, 1, :discard) |> Enum.all?(valid?) end end ``` ## Part 1 ```elixir Enum.count(inputs, &Day02.correct?/1) ``` ## Part 2 ```elixir Enum.count(inputs, fn row -> Enum.any?(0..length(row), fn idx -> row |> List.delete_at(idx) |> Day02.correct?() end) end) ```