From bcd24674ec0a594882b276fd48fe70c6e3d7ec86 Mon Sep 17 00:00:00 2001 From: Tomasz Chojnacki Date: Thu, 6 Apr 2023 11:47:33 +0200 Subject: Finish day 11 --- aoc-2020-gleam/src/util/pos.gleam | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 aoc-2020-gleam/src/util/pos.gleam (limited to 'aoc-2020-gleam/src/util') 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 +} -- cgit v1.2.3