this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

day01: part 1

Preemptively create a *_part_1, because we all know how AOC puzzles go...

+46
+46
lib/day01.ex
··· 1 + defmodule Aoc2025.Day01 do 2 + @moduledoc false 3 + @day 1 4 + @example """ 5 + L68 6 + L30 7 + R48 8 + L5 9 + R60 10 + L55 11 + L1 12 + L99 13 + R14 14 + L82 15 + """ 16 + 17 + def output_parsed_example, do: parse_input(@example) 18 + 19 + def output_parsed_input, do: parse_input(Aoc2025.Utils.get_input(@day)) 20 + 21 + def parse_input(input), do: String.split(input) 22 + 23 + def parse_instruction("L" <> distance), do: {:left, String.to_integer(distance)} 24 + def parse_instruction("R" <> distance), do: {:right, String.to_integer(distance)} 25 + 26 + def inc_if_zero(acc, dial) when dial == 0, do: acc + 1 27 + def inc_if_zero(acc, _dial), do: acc 28 + 29 + def direction_to_op(:left), do: &Kernel.-/2 30 + def direction_to_op(:right), do: &Kernel.+/2 31 + 32 + def double_modulo_after_op(op, dial, distance), do: rem(rem(op.(dial, distance), 100) + 100, 100) 33 + 34 + def compute_part_1(input) do 35 + input 36 + |> Enum.map(&parse_instruction/1) 37 + |> Enum.reduce({0, 50}, fn {direction, distance}, {acc_ans, dial} -> 38 + new_dial = 39 + direction 40 + |> direction_to_op() 41 + |> double_modulo_after_op(dial, distance) 42 + 43 + {inc_if_zero(acc_ans, new_dial), new_dial} 44 + end) 45 + end 46 + end