diff options
author | J.J <thechairman@thechairman.info> | 2023-12-01 18:00:48 -0500 |
---|---|---|
committer | J.J <thechairman@thechairman.info> | 2023-12-01 18:00:48 -0500 |
commit | 826d7698c84b42dadf6b1684c93828e3e2f5ee3a (patch) | |
tree | 372b0b49e0679975194722995462bf00ce22c130 /aoc2023/src | |
parent | f648264a1a91f93f1643163339d52968f1c7bec9 (diff) | |
download | gleam_aoc-826d7698c84b42dadf6b1684c93828e3e2f5ee3a.tar.gz gleam_aoc-826d7698c84b42dadf6b1684c93828e3e2f5ee3a.zip |
day 1 improvements
Diffstat (limited to 'aoc2023/src')
-rw-r--r-- | aoc2023/src/day1/solve.gleam | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/aoc2023/src/day1/solve.gleam b/aoc2023/src/day1/solve.gleam index 29322ce..ed14bde 100644 --- a/aoc2023/src/day1/solve.gleam +++ b/aoc2023/src/day1/solve.gleam @@ -5,24 +5,22 @@ import gleam/string import gleam/regex.{type Match, Match} import gleam/int -fn parse_digits(input: String) { +pub fn part1(input: String) { let assert Ok(re) = regex.from_string("[1-9]") input |> string.split("\n") - |> list.fold(0, fn(acc, s) { - let matches = regex.scan(s, with: re) - - let assert Ok(Match(content: first, ..)) = list.first(matches) - let assert Ok(Match(content: last, ..)) = list.last(matches) - let assert Ok(i) = int.parse(first <> last) - acc + i - }) -} + |> list.fold( + 0, + fn(acc, s) { + let matches = regex.scan(s, with: re) -pub fn part1(input: String) { - input - |> parse_digits + let assert Ok(Match(content: first, ..)) = list.first(matches) + let assert Ok(Match(content: last, ..)) = list.last(matches) + let assert Ok(i) = int.parse(first <> last) + acc + i + }, + ) |> string.inspect } |