From 3fca5aebc32ba5bb13df780a7028bcd54b89a195 Mon Sep 17 00:00:00 2001 From: Tomasz Chojnacki Date: Sat, 17 Dec 2022 13:18:38 +0100 Subject: Submit part 1 of day 16 --- aoc-2022-dotnet/Day14/Program.fs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'aoc-2022-dotnet/Day14') diff --git a/aoc-2022-dotnet/Day14/Program.fs b/aoc-2022-dotnet/Day14/Program.fs index 02e028c..b3ff4f9 100644 --- a/aoc-2022-dotnet/Day14/Program.fs +++ b/aoc-2022-dotnet/Day14/Program.fs @@ -11,8 +11,6 @@ let sandMoveOffsets = Vec2.downLeft Vec2.downRight ] -let notIn set element = not <| Set.contains element set - let buildCaveScan = let parsePath = let py = pint32 |>> (~-) // mirror Y coordinate @@ -39,7 +37,7 @@ let solution1 input = else sandMoveOffsets |> Seq.map ((+) pos) - |> Seq.tryFind (notIn caveScan) + |> Seq.tryFind (Util.notIn caveScan) |> function | Some (nextPos) -> fall nextPos | None -> Some(pos) @@ -62,14 +60,14 @@ let solution2 input = let neighbours pos = sandMoveOffsets |> List.map ((+) pos) - |> List.filter (fun pos -> notIn caveScan pos && Vec2.y pos <> floorY) + |> List.filter (fun pos -> Util.notIn caveScan pos && Vec2.y pos <> floorY) - let rec dfs stack visited = - match stack with - | h :: t -> dfs (List.filter (notIn visited) (neighbours h) @ t) (Set.add h visited) - | [] -> Set.count visited + let rec dfs vis = + function + | h :: t -> dfs (Set.add h vis) (List.filter (Util.notIn vis) (neighbours h) @ t) + | [] -> Set.count vis - dfs [ sandSpawnPos ] Set.empty + dfs Set.empty [ sandSpawnPos ] let test = File.ReadLines("test.txt") assert (solution1 test = 24) -- cgit v1.2.3