Skip to content

Commit ff11396

Browse files
committed
Don't add numbers to themselves in cross product
1 parent 2e3476b commit ff11396

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

2021/day18/day18.raku

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ class Part1 is Solver { method solve( --> Str(Cool)) { magnitude(@.lines.reduce:
104104
# Determine the maximum magnitude of adding any two pairs in the input, noting that addition is
105105
# not commutative.
106106
class Part2 is Solver {
107-
method solve( --> Str(Cool)) { (@.lines X @.lines).map({magnitude(add-pair($_[0], $_[1]))}).max }
107+
method solve( --> Str(Cool)) {
108+
(^@.lines X ^@.lines).grep({.head != .tail})
109+
.map({magnitude(add-pair(@.lines[.head], $.lines[.tail]))})
110+
.max
111+
}
108112
}
109113
110114
class RunContext {

0 commit comments

Comments
 (0)