diff options
Diffstat (limited to 'aoc-2020-gleam/src/util/pos.gleam')
-rw-r--r-- | aoc-2020-gleam/src/util/pos.gleam | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/aoc-2020-gleam/src/util/pos.gleam b/aoc-2020-gleam/src/util/pos.gleam new file mode 100644 index 0000000..a060440 --- /dev/null +++ b/aoc-2020-gleam/src/util/pos.gleam @@ -0,0 +1,26 @@ +import gleam/list +import gleam/set.{Set} + +pub type Pos = + #(Int, Int) + +pub const directions8 = [ + #(1, 0), + #(1, 1), + #(0, 1), + #(-1, 1), + #(-1, 0), + #(-1, -1), + #(0, -1), + #(1, -1), +] + +pub fn add(p1: Pos, p2: Pos) -> Pos { + #(p1.0 + p2.0, p1.1 + p2.1) +} + +pub fn neighbours8(pos: Pos) -> Set(Pos) { + directions8 + |> list.map(with: add(pos, _)) + |> set.from_list +} |