diff options
author | HJ <thechairman@thechairman.info> | 2023-12-01 08:56:32 -0500 |
---|---|---|
committer | HJ <thechairman@thechairman.info> | 2023-12-01 08:56:32 -0500 |
commit | a2bcd6b53e5b94ad4d6b9eb3e847dae210db1704 (patch) | |
tree | 595e9d29f68ab3defaf67ed535af38d99b736254 /aoc2023/src/day1 | |
parent | e3c88c124a61248e0b17fad34df167d40464d946 (diff) | |
download | gleam_aoc-a2bcd6b53e5b94ad4d6b9eb3e847dae210db1704.tar.gz gleam_aoc-a2bcd6b53e5b94ad4d6b9eb3e847dae210db1704.zip |
day 1 improvement
Diffstat (limited to 'aoc2023/src/day1')
-rw-r--r-- | aoc2023/src/day1/solve.gleam | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/aoc2023/src/day1/solve.gleam b/aoc2023/src/day1/solve.gleam index a1092b1..fbc160f 100644 --- a/aoc2023/src/day1/solve.gleam +++ b/aoc2023/src/day1/solve.gleam @@ -2,7 +2,7 @@ import adglent.{First, Second} import gleam/io import gleam/list import gleam/string -import gleam/regex +import gleam/regex.{type Match, Match} import gleam/result import gleam/int @@ -12,20 +12,12 @@ fn parse_digits(input: String) { input |> string.split("\n") |> list.map(fn(s) { - let matches = - regex.scan(s, with: re) - |> list.map(fn(m) { m.content }) + let matches = regex.scan(s, with: re) - case matches { - [one] -> int.parse(one <> one) - _ -> - int.parse( - result.unwrap(list.first(matches), "") <> result.unwrap( - list.last(matches), - "", - ), - ) - } + let assert Ok(Match(content: first, ..)) = list.first(matches) + let assert Ok(Match(content: last, ..)) = list.last(matches) + + int.parse(first <> last) }) } |