Skip to content

Commit 4552a9f

Browse files
committed
[2024] Small cleanup for Day 7
1 parent e5cda69 commit 4552a9f

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

2024/day07/main.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)