diff options
author | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-03-02 21:40:59 +0100 |
---|---|---|
committer | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-03-02 21:40:59 +0100 |
commit | 6c661db5b3e167d45554f7c5e4838dbc3bffa63a (patch) | |
tree | 6ba5eebddc1713f5bd4ee9fe740937a8031d151e /aoc-2020-gleam/src/days/day02.gleam | |
parent | 2ba7501d516afa4ab240faccefb6a3f72223598e (diff) | |
download | gleam_aoc2020-6c661db5b3e167d45554f7c5e4838dbc3bffa63a.tar.gz gleam_aoc2020-6c661db5b3e167d45554f7c5e4838dbc3bffa63a.zip |
Refactor using constructs from Gleam v0.27
Diffstat (limited to 'aoc-2020-gleam/src/days/day02.gleam')
-rw-r--r-- | aoc-2020-gleam/src/days/day02.gleam | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/aoc-2020-gleam/src/days/day02.gleam b/aoc-2020-gleam/src/days/day02.gleam index cedb604..530ab0f 100644 --- a/aoc-2020-gleam/src/days/day02.gleam +++ b/aoc-2020-gleam/src/days/day02.gleam @@ -3,6 +3,8 @@ import gleam/list import gleam/bool import gleam/string as str import ext/listx +import ext/intx +import ext/genericx as genx import ext/resultx as resx import util/input_util import util/parser as p @@ -50,8 +52,8 @@ fn part1(lines: List(String)) -> Int { fn(line) { line.password |> str.to_graphemes - |> listx.count(satisfying: fn(g) { g == line.policy.grapheme }) - |> fn(l) { line.policy.min <= l && l <= line.policy.max } + |> listx.count(satisfying: genx.equals(_, line.policy.grapheme)) + |> intx.is_between(line.policy.min, and: line.policy.max) }, ) } @@ -64,7 +66,8 @@ fn part2(lines: List(String)) -> Int { line.password |> str.to_graphemes |> list.at(index - 1) - |> resx.assert_unwrap == line.policy.grapheme + |> resx.assert_unwrap + |> genx.equals(line.policy.grapheme) } bool.exclusive_or( grapheme_matches(line.policy.min), |