Skip to content

Commit

Permalink
2024 day 05 solution ⭐ ⭐
Browse files Browse the repository at this point in the history
  • Loading branch information
wasi0013 committed Dec 5, 2024
1 parent d7636e8 commit 4948231
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/y2024/day_05.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ defmodule Aoc.Y2024.Day05 do
def find_invalid_pair(list, order) do
Enum.reduce_while(list, [], fn num, visited ->
if Map.has_key?(order, num) do
invalid_nums = Map.get(order, num, [])
invalids = Enum.filter(invalid_nums, &(&1 in visited))
invalids = Map.get(order, num, []) |> Enum.filter(&(&1 in visited))

if invalids != [] do
{:halt, List.first(invalids) |> then(fn x -> {x, num} end)}
Expand Down

0 comments on commit 4948231

Please sign in to comment.