Browse Source

Add a factorial program

ApisNecros 1 year ago
parent
commit
27b0feb9a6
1 changed files with 18 additions and 0 deletions
  1. 18 0
      demos/factorial.js

+ 18 - 0
demos/factorial.js

@@ -0,0 +1,18 @@
+/**
+ * Calculate the factorial of a given number
+ *
+ * Calculates the factorial of a number, outputting the final result.
+ *
+ * Added to the Intcode wiki by myself
+ * @see https://esolangs.org/wiki/Intcode#Example_Programs
+ */
+const Computer = require("../IntComp/Computer");
+
+const program = [3, 25, 1001, 25, 0, 24, 1001, 24, -1, 24, 1006, 24, 20, 2, 25, 24, 25, 1005, 24, 6, 4, 25, 99];
+
+const c = new Computer(program, {
+    inputFromConsole: true,
+    outputToConsole: true,
+});
+
+c.Run();