|
@@ -42,16 +42,16 @@ module.exports = class Computer {
|
|
|
let status = true;
|
|
|
switch (opcode) {
|
|
|
case this.OPCODES.ADD: {
|
|
|
- const operandLeft = this.stack.Next().GetUsingStackValue();
|
|
|
- const operandRight = this.stack.Next().GetUsingStackValue();
|
|
|
+ const operandLeft = this.stack.Next().Get();
|
|
|
+ const operandRight = this.stack.Next().Get();
|
|
|
const position = this.stack.Next().Get();
|
|
|
|
|
|
this.Operation_Add(operandLeft, operandRight, position);
|
|
|
break;
|
|
|
}
|
|
|
case this.OPCODES.MULTIPLY: {
|
|
|
- const operandLeft = this.stack.Next().GetUsingStackValue();
|
|
|
- const operandRight = this.stack.Next().GetUsingStackValue();
|
|
|
+ const operandLeft = this.stack.Next().Get();
|
|
|
+ const operandRight = this.stack.Next().Get();
|
|
|
const position = this.stack.Next().Get();
|
|
|
|
|
|
this.Operation_Multiply(operandLeft, operandRight, position);
|
|
@@ -122,3 +122,23 @@ module.exports = class Computer {
|
|
|
console.log(this.stack.Dump());
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+/**
|
|
|
+ * Check whether the value at a specific spot in a number is non-zero
|
|
|
+ *
|
|
|
+ * Similar to the bitwise & operator, checks a "place" in a decimal number
|
|
|
+ * to see if it has a non-zero value.
|
|
|
+ *
|
|
|
+ * @example
|
|
|
+ * const test = 107;
|
|
|
+ * console.log(DecimalPlaceIsNonZero(test, 1)) // true
|
|
|
+ * console.log(DecimalPlaceIsNonZero(test, 2)) // false
|
|
|
+ * console.log(DecimalPlaceIsNonZero(test, 3)) // true
|
|
|
+ *
|
|
|
+ * @param {number} input The number to check
|
|
|
+ * @param {number} place The power of 10 to check against
|
|
|
+ * @returns {boolean} Whether the value in that number's place is non-zero
|
|
|
+ */
|
|
|
+function DecimalPlaceIsNonZero(input, place) {
|
|
|
+ return !!Math.floor((input % 10**place) / 10**(place - 1));
|
|
|
+}
|