@@ -22,7 +22,7 @@ func part1(input string) int64 {
22
22
23
23
sum := int64 (0 )
24
24
for _ , equation := range equations {
25
- if isValidEquation (0 , equation .operands , equation .testValue , false ) {
25
+ if isValidEquation (equation . operands [ 0 ] , equation .operands [ 1 :] , equation .testValue , false ) {
26
26
sum += equation .testValue
27
27
}
28
28
}
@@ -38,7 +38,7 @@ func part2(input string) int64 {
38
38
39
39
sum := int64 (0 )
40
40
for _ , equation := range equations {
41
- if isValidEquation (0 , equation .operands , equation .testValue , true ) {
41
+ if isValidEquation (equation . operands [ 0 ] , equation .operands [ 1 :] , equation .testValue , true ) {
42
42
sum += equation .testValue
43
43
}
44
44
}
@@ -58,20 +58,16 @@ func isValidEquation(current int64, operands []int64, target int64, allowConcat
58
58
return true
59
59
}
60
60
61
+ if isValidEquation (current * operand , operands , target , allowConcat ) {
62
+ return true
63
+ }
64
+
61
65
if allowConcat {
62
66
if isValidEquation (current * getMultiplier (operand )+ operand , operands , target , allowConcat ) {
63
67
return true
64
68
}
65
69
}
66
70
67
- if current == 0 {
68
- current = 1
69
- }
70
-
71
- if isValidEquation (current * operand , operands , target , allowConcat ) {
72
- return true
73
- }
74
-
75
71
return false
76
72
}
77
73
0 commit comments