diff options
author | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-02-21 19:46:12 +0100 |
---|---|---|
committer | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-02-21 19:46:12 +0100 |
commit | 16509ecd4f31ef421a464a98c8e0ea73bb5cb111 (patch) | |
tree | 7ac2145ed18cf868abe0b877fecb5988d11fd2ac /aoc-2020-gleam/src/days/day04.gleam | |
parent | 9c94df2676e8b857eac6c94e827086bf0e8cb850 (diff) | |
download | gleam_aoc2020-16509ecd4f31ef421a464a98c8e0ea73bb5cb111.tar.gz gleam_aoc2020-16509ecd4f31ef421a464a98c8e0ea73bb5cb111.zip |
Refactor previous days
Diffstat (limited to 'aoc-2020-gleam/src/days/day04.gleam')
-rw-r--r-- | aoc-2020-gleam/src/days/day04.gleam | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/aoc-2020-gleam/src/days/day04.gleam b/aoc-2020-gleam/src/days/day04.gleam index 322d5c9..53abb0c 100644 --- a/aoc-2020-gleam/src/days/day04.gleam +++ b/aoc-2020-gleam/src/days/day04.gleam @@ -20,25 +20,25 @@ type Passport { fn parse_passports(from text: String) -> List(Passport) { let key_parser = - p.any_string_of_exactly(length: 3) + p.any_str_of_len(3) |> p.labeled(with: "key") let value_parser = - p.string1_until_whitespace() + p.str1_until_ws() |> p.labeled(with: "value") let field_parser = key_parser - |> p.then_skip(p.grapheme_literal(":")) + |> p.then_skip(p.literal(":")) |> p.then(value_parser) |> p.labeled(with: "field") let passport_parser = field_parser - |> p.separated1(by: p.whitespace_grapheme()) + |> p.sep1(by: p.ws_gc()) |> p.map(with: function.compose(map.from_list, Passport)) |> p.labeled(with: "passport") let input_parser = passport_parser - |> p.separated1(by: p.string_literal("\n\n")) - |> p.then_skip(p.optional(p.whitespace_grapheme())) + |> p.sep1(by: p.literal("\n\n")) + |> p.then_skip(p.opt(p.ws_gc())) |> p.labeled(with: "input") text @@ -61,7 +61,7 @@ fn is_valid1(passport: Passport) -> Bool { fn is_valid2(passport: Passport) -> Bool { let int_between = fn(min, max) { p.int() - |> p.matching(rule: fn(number) { min <= number && number <= max }) + |> p.satisfying(rule: fn(number) { min <= number && number <= max }) |> p.ignore } @@ -73,32 +73,32 @@ fn is_valid2(passport: Passport) -> Bool { "hgt", p.or( int_between(150, 193) - |> p.then(p.string_literal("cm")), + |> p.then(p.literal("cm")), int_between(59, 76) - |> p.then(p.string_literal("in")), + |> p.then(p.literal("in")), ) |> p.ignore, ), #( "hcl", - p.then( - p.grapheme_literal("#"), - p.grapheme_in(range: "0123456789abcdef") - |> p.repeated(times: 6), + p.literal("#") + |> p.then( + p.gc_in(range: "0123456789abcdef") + |> p.repeat(times: 6), ) |> p.ignore, ), #( "ecl", eye_colors - |> list.map(with: p.string_literal) + |> list.map(with: p.literal) |> p.any |> p.ignore, ), #( "pid", p.digit() - |> p.string_of_exactly(length: 9) + |> p.str_of_len(9) |> p.ignore, ), ] |