Skip to content

Commit

Permalink
#33: Documentation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jaccomoc committed Dec 2, 2023
1 parent 6375722 commit 7f9cbd8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/_posts/2023-12-02-advent-of-code-2023-day1.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ In the end this is the solution I came up with:
```groovy
def vals = [zero:0, one:1, two:2, three:3, four:4, five:5, six:6, seven:7, eight:8, nine:9] + (10.map{ ["$it",it] } as Map)
def n = vals.map{it[0]}.join('|') // number pattern
stream(nextLine).map{ [/^.*?($n)/r, vals[$1], /.*($n)((?!($n)).)*$/r, vals[$1]] }
stream(nextLine).map{ [/^.*?($n)/r, vals[$1], /.*($n).*$/r, vals[$1]] }
.map{ 10 * it[1] + it[3] }
.sum()
```
Expand All @@ -106,8 +106,9 @@ One for the first digit `/^.*?($n)/` which uses a non-greedy match for character
therefore find the first set of characters that matches our digits pattern stored in `n`.
The `$1` value then ends up being the matching value which we look up in `vals` to get the numeric value.

The second regex is `/.*($n)((?!($n)).)*$/` where we use a greedy match to grab everything possible at the start of
the line and then find the characters matching `$n` where there are no further matches for `$n` that occur after.
The second regex is `/.*($n).*$/` where we use a greedy match to grab everything possible at the start of
the line and then find the characters matching `$n`.
Since we used a greedy match we know that there are no matches earlier in the line.
Again `$1` will have the result.

The `map` method converts each line to a list of four values being:
Expand Down

0 comments on commit 7f9cbd8

Please sign in to comment.