Mirror-machine
Jump to navigation
Jump to search
A Mirror-machine is an extremely simple program type invented by User:ReplayShells to check decision, addition, subtraction, loops, input and outputs. Process:
- Input vars a,b (b is unsigned.)
- Increment a
- Decrement b
- If a is not 0:
- Print a
- Set a to 0
- If b is not 1:
- Print b
- While b is not 0
- Print b
- Decrement b
- Input a,b
- Print a - b
- Print ABC
- Terminate program
The program, when expressed in pseudocode, adheres to the following principles:
a ← input integer, where a ∈ ℤ b ← input integer, where b ∈ ℤ ∧ b ≥ 0 a ← a + 1 b ← b - 1 if a ≠ 0 then print a a ← 0 end if if b ≠ 1 then print b end if while b ≠ 0 do print b b ← b - 1 end while a ← input integer, where a ∈ ℤ b ← input integer, where b ∈ ℤ ∧ b ≥ 0 print a - b print "ABC" terminate program
Implementations
C
#include <stdio.h> int main(void) { int a; unsigned b; scanf("%d %u", &a, &b); ++a; --b; if(a != 0) { printf("%d\n", a); a = 0; } if(b != 1) printf("%u\n", b); while(b != 0) { printf("%u\n", b); --b; } scanf("%d %u", &a, &b); printf("%d\n", a - b); printf("ABC\n"); return 0; }
Phile
OPEN "stdin.stream"; OPEN "stdout.stream"; OPEN "a"; OPEN "b"; /// Input variables a, b. OVERWRITE "a" READ "stdin.stream"; OVERWRITE "b" READ "stdin.stream"; /// Increment a. OVERWRITE "a" READ "a" + 1; /// Decrement b. OVERWRITE "b" READ "b" - 1; /// Test of a. READ "a" = 0? 11; OVERWRITE "stdout.stream" READ "a" + "\n"; OVERWRITE "a" 0; /// Line 11: /// Test of b. READ "b" = 1? 13; OVERWRITE "stdout.stream" READ "b" + "\n"; /// Line 13: /// While loop. READ "b" = 0? 17; OVERWRITE "stdout.stream" READ "b" + "\n"; OVERWRITE "b" READ "b" - 1; READ "b" ! 0? 13; /// Line 17: /// Input a, b. OVERWRITE "a" READ "stdin.stream"; OVERWRITE "b" READ "stdin.stream"; /// Print a - b. OVERWRITE "stdout.stream" READ "a" - READ "b"; OVERWRITE "stdout.stream" "\n"; /// Print "ABC". OVERWRITE "stdout.stream" "ABC" + "\n"; /// Terminate program. CLOSE "stdin.stream"; CLOSE "stdout.stream"; CLOSE "a"; CLOSE "b";
Python
a, b = int(input()), int(input()) a += 1 b -= 1 if a != 0: print(a) a = 0 if b != 1: print(b) while b != 0: print(b) b -= 1 a, b = int(input()), int(input()) print(a-b) print("ABC")
Rec
R/R\ [1:^1:P0 1;0^] [0:\^0:P0^] [0:^0:P\] R1;R0; [0:^\1:\1;] [^]P 65p 66p 67p