diff --git a/src/solve_2025_01.gleam b/src/solve_2025_01.gleam index 0c7ce91..3fb5891 100644 --- a/src/solve_2025_01.gleam +++ b/src/solve_2025_01.gleam @@ -12,16 +12,19 @@ pub fn part_one(input: String) -> Int { } pub fn part_two(input: String) -> Int { - let rotations = parse(input) - let #(_, seen) = { - use accumulator, rotation <- list.fold(rotations, #(50, 0)) - let #(previous, seen) = accumulator - echo #(previous, seen, rotation, rotation / 100) - // const via_zero = ??? - #({ previous + rotation } % 100, seen + { rotation / 100 }) - } - - seen + input + |> parse + |> list.prepend(0) + |> list.scan(50, int.add) + |> list.window_by_2 + |> list.fold(0, fn(accumulator, pair) { + let #(from, to) = pair + list.range(from, to) + |> list.drop(1) + |> echo + |> list.count(fn(position) { position % 100 == 0 }) + |> int.add(accumulator) + }) } fn count_zeros(numbers: List(Int)) -> #(Int, Int) { @@ -45,10 +48,3 @@ fn parse(input: String) -> List(Int) { Error(_) -> [] } } - -fn rotate(value: Int, cycle: Int) -> #(Int, Int) { - case value % cycle { - value if value < 0 -> #(value % cycle, value / cycle) - _ -> #(value, 0) - } -} diff --git a/test/test_2025_01.gleam b/test/test_2025_01.gleam index f9c49dc..42971a3 100644 --- a/test/test_2025_01.gleam +++ b/test/test_2025_01.gleam @@ -21,10 +21,11 @@ pub fn part_one_test() { |> solve_2025_01.part_one assert result == 3 } -// pub fn part_two_test() { -// let result = -// input -// |> string.trim -// |> solve_2025_01.part_two -// assert result == 6 -// } + +pub fn part_two_test() { + let result = + input + |> string.trim + |> solve_2025_01.part_two + assert result == 6 +}