We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 260a177 commit 74bbe7bCopy full SHA for 74bbe7b
src/day3.gleam
@@ -5,18 +5,15 @@ import gleam/regexp
5
import gleam/result
6
7
pub fn part1(input: String) -> Int {
8
- let assert Ok(re) = regexp.from_string("mul\\((\\d+),(\\d+)\\)")
9
- regexp.scan(re, input)
10
- |> list.map(fn(match) {
11
- match.submatches
12
- |> list.map(fn(submatch) { option.unwrap(submatch, "") })
13
- |> list.filter_map(int.parse)
14
- })
15
- |> list.map(fn(mul) {
16
- mul |> list.reduce(fn(acc, m) { acc * m }) |> result.unwrap(0)
+ input
+ |> parse_input
+ |> list.map(fn(token) {
+ case token {
+ Mul(a, b) -> a * b
+ _ -> 0
+ }
17
})
18
- |> list.reduce(fn(acc, v) { acc + v })
19
- |> result.unwrap(0)
+ |> list.fold(0, fn(acc, v) { acc + v })
20
}
21
22
pub fn part2(input: String) -> Int {
0 commit comments