File tree Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -31,19 +31,14 @@ trait Day09 {
31
31
recurse(input).length
32
32
}
33
33
34
- def solve2 (input : String ): Long = {
35
- if (! input.contains(" (" )) input.length
34
+ def solve2 (input : String , accum : Long = 0 ): Long = {
35
+ if (! input.contains(" (" )) accum + input.length
36
36
else {
37
- var len = 0L
38
- var working = input
39
- while (working.contains(" (" )) {
40
- val open = working.indexOf(" (" )
41
- val close = working.indexOf(" )" )
42
- val marker = working.slice(open + 1 , close).split(" x" ).map(_.toInt)
43
- len += open + solve2(working.slice(close + 1 , close + 1 + marker(0 )) * marker(1 ))
44
- working = working.drop(close + 1 + marker(0 ))
45
- }
46
- len + working.length
37
+ val open = input.indexOf(" (" )
38
+ val close = input.indexOf(" )" )
39
+ val marker = input.slice(open + 1 , close).split(" x" ).map(_.toInt)
40
+ solve2(input.drop(close + 1 + marker(0 )),
41
+ accum + open + solve2(input.slice(close + 1 , close + 1 + marker(0 )) * marker(1 ), 0 ))
47
42
}
48
43
}
49
44
}
You can’t perform that action at this time.
0 commit comments