aboutsummaryrefslogtreecommitdiff
path: root/aoc-2022-dotnet/Day12
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2022-12-17 13:18:38 +0100
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2022-12-17 13:18:38 +0100
commit3fca5aebc32ba5bb13df780a7028bcd54b89a195 (patch)
tree107e53caab2445a771a7eb7c02c901dd4e53ff23 /aoc-2022-dotnet/Day12
parent689368eb3bbd9695ef2183ce03596a34be9292f5 (diff)
downloadgleam_aoc2020-3fca5aebc32ba5bb13df780a7028bcd54b89a195.tar.gz
gleam_aoc2020-3fca5aebc32ba5bb13df780a7028bcd54b89a195.zip
Submit part 1 of day 16
Diffstat (limited to 'aoc-2022-dotnet/Day12')
-rw-r--r--aoc-2022-dotnet/Day12/Program.fs14
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