aboutsummaryrefslogtreecommitdiff
path: root/aoc-2020-gleam/src/util/hex.gleam
diff options
context:
space:
mode:
Diffstat (limited to 'aoc-2020-gleam/src/util/hex.gleam')
-rw-r--r--aoc-2020-gleam/src/util/hex.gleam21
1 files changed, 21 insertions, 0 deletions
diff --git a/aoc-2020-gleam/src/util/hex.gleam b/aoc-2020-gleam/src/util/hex.gleam
new file mode 100644
index 0000000..21db192
--- /dev/null
+++ b/aoc-2020-gleam/src/util/hex.gleam
@@ -0,0 +1,21 @@
+pub opaque type Hex {
+ Hex(q: Int, r: Int, s: Int)
+}
+
+pub const zero = Hex(q: 0, r: 0, s: 0)
+
+pub const e = Hex(q: 1, r: 0, s: -1)
+
+pub const se = Hex(q: 0, r: 1, s: -1)
+
+pub const sw = Hex(q: -1, r: 1, s: 0)
+
+pub const w = Hex(q: -1, r: 0, s: 1)
+
+pub const nw = Hex(q: 0, r: -1, s: 1)
+
+pub const ne = Hex(q: 1, r: -1, s: 0)
+
+pub fn add(a: Hex, b: Hex) -> Hex {
+ Hex(q: a.q + b.q, r: a.r + b.r, s: a.s + b.s)
+}