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 4948231 commit 7e147b4
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions lib/y2024/day_05.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ defmodule Aoc.Y2024.Day05 do
def is_valid?(list, order) do
Enum.reduce_while(list, {[], true}, fn num, {visited, is_valid} ->
if Map.has_key?(order, num) do
restricted = Map.get(order, num, [])

if Enum.any?(restricted, &(&1 in visited)) do
if Enum.any?(Map.get(order, num, []), &(&1 in visited)) do
{:halt, {visited, false}}
else
{:cont, {[num | visited], is_valid}}
Expand Down

0 comments on commit 7e147b4

Please sign in to comment.