diff options
author | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-04-06 11:47:33 +0200 |
---|---|---|
committer | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-04-06 11:47:33 +0200 |
commit | bcd24674ec0a594882b276fd48fe70c6e3d7ec86 (patch) | |
tree | b89a268e3a11267a34e3cd1a2d42f6ed432c97fd /aoc-2020-gleam/src/util | |
parent | feb51c3a6e7eb8a7ac3fa22ac5d12d20e84eb65f (diff) | |
download | gleam_aoc2020-bcd24674ec0a594882b276fd48fe70c6e3d7ec86.tar.gz gleam_aoc2020-bcd24674ec0a594882b276fd48fe70c6e3d7ec86.zip |
Finish day 11
Diffstat (limited to 'aoc-2020-gleam/src/util')
-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 +} |