aboutsummaryrefslogtreecommitdiff
path: root/aoc-2022-dotnet/Day14
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/Day14
parent689368eb3bbd9695ef2183ce03596a34be9292f5 (diff)
downloadgleam_aoc2020-3fca5aebc32ba5bb13df780a7028bcd54b89a195.tar.gz
gleam_aoc2020-3fca5aebc32ba5bb13df780a7028bcd54b89a195.zip
Submit part 1 of day 16
Diffstat (limited to 'aoc-2022-dotnet/Day14')
-rw-r--r--aoc-2022-dotnet/Day14/Program.fs16
1 files changed, 7 insertions, 9 deletions
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)