From ab0c405725d3d137eafa2b87e1bdee0dcf21cb45 Mon Sep 17 00:00:00 2001 From: scarf Date: Wed, 4 Dec 2024 09:55:38 +0900 Subject: [PATCH] docs(2024/03): add missing `.toInt` --- docs/2024/puzzles/day03.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/2024/puzzles/day03.md b/docs/2024/puzzles/day03.md index c00dc8d16..9ee852ac8 100644 --- a/docs/2024/puzzles/day03.md +++ b/docs/2024/puzzles/day03.md @@ -40,7 +40,7 @@ val multiplications = mulPattern.findAllIn(input) Take note that `multiplications` is an instance of `MatchIterator` over the input string. If we turn it into a sequence, it will be a sequence of substrings - but what we actually need to do is extract the numbers from within each substring, multiply them, and then sum them all together. Fortunately, the `collect` method from the Scala standard collection library will be just perfect for that. What's more, we can reuse the same regex. In Scala, regular expressions can be seamlessly used in pattern matching, which makes working with strings a breeze. ```scala -val result1 = multiplications.collect { case mulPattern(a, b) => a * b }.sum +val result1 = multiplications.collect { case mulPattern(a, b) => a.toInt * b.toInt }.sum ``` And here it is - the result for **Part 1**.