Fixed subtraction

This commit is contained in:
Sasha Koshka 2022-11-21 13:49:36 -05:00
parent 317ad4674d
commit eea76b7e5b

13
tree.go
View File

@ -259,11 +259,22 @@ func (operation *Operation) Solution () (solution int64, err error) {
solution += subSolution solution += subSolution
} }
case OpcodeSubtract: case OpcodeSubtract:
for _, operand := range operation.operands { if len(operation.operands) == 1 {
solution, err = operation.operands[0].Solution()
solution *= -1
if err != nil { return }
break
}
for index, operand := range operation.operands {
subSolution, err = operand.Solution() subSolution, err = operand.Solution()
if err != nil { return } if err != nil { return }
if index == 0 {
solution = subSolution
} else {
solution -= subSolution solution -= subSolution
} }
}
case OpcodeMultiply: case OpcodeMultiply:
solution = 1 solution = 1
for _, operand := range operation.operands { for _, operand := range operation.operands {