public MyNumberItem(MyNumberItem left, MyNumberItem right, int numbersUsed, int currentValue, MyNumberOperators operand, int mask, int startIndex) { this.left = left; this.right = right; this.currentValue = currentValue; this.operand = operand; this.mask = mask; this.numbersUsed = numbersUsed; this.startIndex = startIndex; }
public MyNumberItem CalculateNew(MyNumberItem right, MyNumberOperators op, int newStartIndex) { int newValue; switch (op) { case MyNumberOperators.ADD: newValue = this.currentValue + right.currentValue; break; case MyNumberOperators.SUB: newValue = this.currentValue - right.currentValue; if (newValue <= 0) // x - (y - z) is same as x + (z - y) and zero does not make any sense { return(null); } break; case MyNumberOperators.MULTIPLY: newValue = this.currentValue * right.currentValue; break; case MyNumberOperators.DIVIDE: if (right.currentValue == 0) { return(null); } newValue = currentValue / right.currentValue; // not fully dividable if (newValue * right.currentValue != currentValue) { return(null); } break; default: return(null); } MyNumberItem item = new MyNumberItem(this, right, numbersUsed + right.numbersUsed, newValue, op, mask | right.mask, newStartIndex); return(item); }