@@ -22,7 +22,7 @@ func part1(input string) int64 {
2222
2323 sum := int64 (0 )
2424 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 ) {
2626 sum += equation .testValue
2727 }
2828 }
@@ -38,7 +38,7 @@ func part2(input string) int64 {
3838
3939 sum := int64 (0 )
4040 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 ) {
4242 sum += equation .testValue
4343 }
4444 }
@@ -58,20 +58,16 @@ func isValidEquation(current int64, operands []int64, target int64, allowConcat
5858 return true
5959 }
6060
61+ if isValidEquation (current * operand , operands , target , allowConcat ) {
62+ return true
63+ }
64+
6165 if allowConcat {
6266 if isValidEquation (current * getMultiplier (operand )+ operand , operands , target , allowConcat ) {
6367 return true
6468 }
6569 }
6670
67- if current == 0 {
68- current = 1
69- }
70-
71- if isValidEquation (current * operand , operands , target , allowConcat ) {
72- return true
73- }
74-
7571 return false
7672}
7773
0 commit comments