aboutsummaryrefslogtreecommitdiff
path: root/aoc-2020-gleam/src/days/day02.gleam
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-02-22 14:01:12 +0100
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-02-22 14:01:12 +0100
commitefde7d6c018e360efbf590a67d128de41e6da7af (patch)
tree1ae6d7d3eba15c48b1219e4e9e1d956809f76064 /aoc-2020-gleam/src/days/day02.gleam
parent5746dbca0ddaef455b6f26fba3945f3533d0b2c1 (diff)
downloadgleam_aoc2020-efde7d6c018e360efbf590a67d128de41e6da7af.tar.gz
gleam_aoc2020-efde7d6c018e360efbf590a67d128de41e6da7af.zip
Refactor previous days
Diffstat (limited to 'aoc-2020-gleam/src/days/day02.gleam')
-rw-r--r--aoc-2020-gleam/src/days/day02.gleam14
1 files changed, 7 insertions, 7 deletions
diff --git a/aoc-2020-gleam/src/days/day02.gleam b/aoc-2020-gleam/src/days/day02.gleam
index 6d2e743..3099d23 100644
--- a/aoc-2020-gleam/src/days/day02.gleam
+++ b/aoc-2020-gleam/src/days/day02.gleam
@@ -18,12 +18,12 @@ type Line {
fn parse_line(string: String) -> Line {
let policy_parser =
p.int()
- |> p.then_skip(p.literal("-"))
+ |> p.skip(p.literal("-"))
|> p.then(p.int())
- |> p.then_skip(p.literal(" "))
+ |> p.skip(p.literal(" "))
|> p.then_3rd(p.any_gc())
- |> p.then_skip(p.literal(": "))
- |> p.map3(with: fn(min, max, grapheme) { Policy(min, max, grapheme) })
+ |> p.skip(p.literal(": "))
+ |> p.map3(with: Policy)
|> p.labeled(with: "policy")
let password_parser = p.labeled(p.any_str_greedy(), with: "password")
@@ -31,7 +31,7 @@ fn parse_line(string: String) -> Line {
let line_parser =
policy_parser
|> p.then(password_parser)
- |> p.map2(fn(policy, password) { Line(policy, password) })
+ |> p.map2(with: Line)
|> p.labeled(with: "line")
assert Ok(policy) = p.parse_entire(string, with: line_parser)
@@ -60,10 +60,10 @@ fn part2(lines: List(String)) -> Int {
solve(
lines,
fn(line) {
- let grapheme_matches = fn(idx) {
+ let grapheme_matches = fn(index) {
line.password
|> str.to_graphemes
- |> list.at(idx - 1)
+ |> list.at(index - 1)
|> resx.assert_unwrap == line.policy.grapheme
}
bool.exclusive_or(