Multi-machine

From Esolang
Jump to navigation Jump to search

A Multi-machine is an extremely simple program type invented bt User:A to check decision, looping, addition, subtraction, termination, input, and output in a simpler way compared to Truth-machine.

Concept

Rules:

  • Never use a for loop.

The process, expressed in pseudocode, constitutes:

a ← input integer, where a ∈ ℤ
b ← input integer, where b ∈ ℤ ∧ b ≥ 0
c ← 0,             where c ∈ ℤ

while b ≠ 0 do
  print c
  c ← c + a
  b ← b - 1
end while

print c
terminate program

Variants

In languages without input capabilities, the input should be placed somewhere in the code or in the memory. In languages without output capabilities, the result should be saved in the memory, or even somewhere in the code.

Implementations

An exemplary implementation in Common Lisp resolves to this:

(let ((a (parse-integer (read-line)))
      (b (parse-integer (read-line)))
      (c 0))
  (declare (type (integer * *) a))
  (declare (type (integer 0 *) b))
  (declare (type (integer * *) c))
  
  (loop until (zerop b) do
    (format T "~&~d" c)
    (incf c a)
    (decf b 1))
  
  (format T "~&~d" c))

See also

  • Mirror-machine, a conceptually similar type of program
  • Truth-machine, a conceptually similar type of program which employs infinite loops