diff options
Diffstat (limited to 'aoc-2022-dotnet/Day12/Program.fs')
-rw-r--r-- | aoc-2022-dotnet/Day12/Program.fs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/aoc-2022-dotnet/Day12/Program.fs b/aoc-2022-dotnet/Day12/Program.fs index ca827ba..77417c5 100644 --- a/aoc-2022-dotnet/Day12/Program.fs +++ b/aoc-2022-dotnet/Day12/Program.fs @@ -47,24 +47,24 @@ type Graph<'T> = |> Graph.withNewEdges graph static member distance spred epred (Graph nodes: Graph<'T>) = - let rec bfsExplore queue explored = - match queue with + let rec bfsExplore explored = + function | [] -> None - | (vi, depth) :: qt -> + | (vi, depth) :: queue -> (let (v, neighbours) = nodes[vi] if epred v then Some(depth) else bfsExplore + (explored + neighbours) (neighbours - explored |> Seq.map (fun n -> (n, depth + 1)) - |> Seq.append qt - |> List.ofSeq) - (explored + neighbours)) + |> Seq.append queue + |> List.ofSeq)) let si = Map.findKey (fun _ (v, _) -> spred v) nodes - bfsExplore [ (si, 0) ] (Set.singleton si) + bfsExplore (Set.singleton si) [ (si, 0) ] let solution distanceCalculation = array2D |