From 6c661db5b3e167d45554f7c5e4838dbc3bffa63a Mon Sep 17 00:00:00 2001 From: Tomasz Chojnacki Date: Thu, 2 Mar 2023 21:40:59 +0100 Subject: Refactor using constructs from Gleam v0.27 --- aoc-2020-gleam/src/days/day02.gleam | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'aoc-2020-gleam/src/days/day02.gleam') 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), -- cgit v1.2.3