aboutsummaryrefslogtreecommitdiff
path: root/aoc-2020-gleam/src/days/day03.gleam
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-04-06 11:47:33 +0200
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-04-06 11:47:33 +0200
commitbcd24674ec0a594882b276fd48fe70c6e3d7ec86 (patch)
treeb89a268e3a11267a34e3cd1a2d42f6ed432c97fd /aoc-2020-gleam/src/days/day03.gleam
parentfeb51c3a6e7eb8a7ac3fa22ac5d12d20e84eb65f (diff)
downloadgleam_aoc2020-bcd24674ec0a594882b276fd48fe70c6e3d7ec86.tar.gz
gleam_aoc2020-bcd24674ec0a594882b276fd48fe70c6e3d7ec86.zip
Finish day 11
Diffstat (limited to 'aoc-2020-gleam/src/days/day03.gleam')
-rw-r--r--aoc-2020-gleam/src/days/day03.gleam10
1 files changed, 2 insertions, 8 deletions
diff --git a/aoc-2020-gleam/src/days/day03.gleam b/aoc-2020-gleam/src/days/day03.gleam
index 3a62419..0778eea 100644
--- a/aoc-2020-gleam/src/days/day03.gleam
+++ b/aoc-2020-gleam/src/days/day03.gleam
@@ -9,9 +9,7 @@ import ext/intx
import ext/resultx as resx
import ext/iteratorx as iterx
import util/input_util
-
-type Pos =
- #(Int, Int)
+import util/pos.{Pos}
const starting_pos = #(0, 0)
@@ -19,10 +17,6 @@ const base_slope = #(3, 1)
const all_slopes = [#(1, 1), base_slope, #(5, 1), #(7, 1), #(1, 2)]
-fn add(p1: Pos, p2: Pos) -> Pos {
- #(p1.0 + p2.0, p1.1 + p2.1)
-}
-
type Area {
Area(trees: Set(Pos), cycle: Int, height: Int)
}
@@ -68,7 +62,7 @@ fn is_valid(pos: Pos, in area: Area) -> Bool {
fn tree_count(in area: Area, with slope: Pos) -> Int {
starting_pos
- |> iter.iterate(with: add(_, slope))
+ |> iter.iterate(with: pos.add(_, slope))
|> iter.take_while(satisfying: is_valid(_, in: area))
|> iterx.count(satisfying: has_tree(in: area, at: _))
}