aboutsummaryrefslogtreecommitdiff
path: root/aoc-2022-dotnet/Common
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2022-12-22 13:43:09 +0100
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2022-12-22 13:43:09 +0100
commitc8a6d6010bddc3789f4770e66da3766fc4f470ad (patch)
tree1448ef78036248b46343d7e981e31d96ebc88966 /aoc-2022-dotnet/Common
parent9e378a9f80260c2f729daaf83d8e74f7bad70b16 (diff)
downloadgleam_aoc2020-c8a6d6010bddc3789f4770e66da3766fc4f470ad.tar.gz
gleam_aoc2020-c8a6d6010bddc3789f4770e66da3766fc4f470ad.zip
Finish day 18
Diffstat (limited to 'aoc-2022-dotnet/Common')
-rw-r--r--aoc-2022-dotnet/Common/Common.fsproj1
-rw-r--r--aoc-2022-dotnet/Common/Vec3.fs33
2 files changed, 34 insertions, 0 deletions
diff --git a/aoc-2022-dotnet/Common/Common.fsproj b/aoc-2022-dotnet/Common/Common.fsproj
index 32057cf..510a1ea 100644
--- a/aoc-2022-dotnet/Common/Common.fsproj
+++ b/aoc-2022-dotnet/Common/Common.fsproj
@@ -6,6 +6,7 @@
</PropertyGroup>
<ItemGroup>
+ <Compile Include="Vec3.fs" />
<Compile Include="Vec2.fs" />
<Compile Include="Util.fs" />
</ItemGroup>
diff --git a/aoc-2022-dotnet/Common/Vec3.fs b/aoc-2022-dotnet/Common/Vec3.fs
new file mode 100644
index 0000000..3a05315
--- /dev/null
+++ b/aoc-2022-dotnet/Common/Vec3.fs
@@ -0,0 +1,33 @@
+namespace Common
+
+type Vec3 =
+ | Vec3 of int * int * int
+
+ static member x(Vec3 (x, _, _)) = x
+ static member y(Vec3 (_, y, _)) = y
+ static member z(Vec3 (_, _, z)) = z
+
+ static member ones = Vec3(1, 1, 1)
+
+ static member directions6 =
+ [ Vec3(-1, 0, 0)
+ Vec3(1, 0, 0)
+ Vec3(0, -1, 0)
+ Vec3(0, 1, 0)
+ Vec3(0, 0, -1)
+ Vec3(0, 0, 1) ]
+
+ static member combine fn (Vec3 (x1, y1, z1)) (Vec3 (x2, y2, z2)) = Vec3(fn x1 x2, fn y1 y2, fn z1 z2)
+
+ static member inline (+)(v1, v2) = Vec3.combine (+) v1 v2
+ static member inline (-)(v1, v2) = Vec3.combine (-) v1 v2
+
+ static member neighbours6 v = List.map ((+) v) Vec3.directions6
+
+ static member boundedBy minBound maxBound (Vec3 (x, y, z)) =
+ x >= Vec3.x minBound
+ && x <= Vec3.x maxBound
+ && y >= Vec3.y minBound
+ && y <= Vec3.y maxBound
+ && z >= Vec3.z minBound
+ && z <= Vec3.z maxBound