Divmeq: Difference between revisions
m Modified the interpreter to fix float-related problems, at the expense of some TC-ness |
m flipped signs |
||
Line 14: | Line 14: | ||
0: 2 2 |
0: 2 2 |
||
1: 1 1</pre> |
1: 1 1</pre> |
||
This halts if 0 and doesn't halt if 1 |
This halts if 0 and doesn't halt if 1. |
||
===XKCD Random Number=== |
===XKCD Random Number=== |
||
<pre>0: 0.25 1</pre> |
<pre>0: 0.25 1</pre> |
||
Line 43: | Line 43: | ||
global x |
global x |
||
global inst |
global inst |
||
if x % A |
if x % A > 1e-16 or x % A < (A - 1e-16): # Hinders TC, but fixes issues with floats |
||
x /= A |
x /= A |
||
inst = B |
inst = B |
Revision as of 16:52, 26 July 2024
Divmeq (derived from 'DIVide and branch, if Modulo EQuals 0') is a one-instruction Turing-complete esoteric programming language created by User:TheCanon2.
Commands
Divmeq has a single accumulator, x
. Lines in Divmeq have two parameters, A
and B
.
If x is divisible by A, divide X by A and jump to line B. Else, move 1 line forward.
Line numbers start at 0 and increment by 1 for each line in the program. If the line number is greater than the length of the program, halt. The line number is generally omitted.
Divmeq accepts a numeric input at the beginning of a program, which is written to the accumulator. The accumulator is set to 1 if no input is given.
Examples
Truth machine
0: 2 2 1: 1 1
This halts if 0 and doesn't halt if 1.
XKCD Random Number
0: 0.25 1
Sets the accumulator to 4.
Computational class
Divmeq is Turing-complete for it can simulate a one-register Minsky machine.
0: 1/n 1
Multiply by n
0: n A
Check if x is divisible by n, and if so, divide by n and jump to A
Implementations
The following Python script is an interpreter.
prgm = [[]] prgm.pop(0) while True: line = input('%s: ' % len(prgm)) # Does not accept line numbering if line != "eof": line = list(line.split(" ")) prgm.append([float(line[0]), int(line[1])]) else: break init = input('>i ') # Grabs user input if init == "": x = 1 else: x = float(init) # Executes the program def divmeq(A, B): global x global inst if x % A > 1e-16 or x % A < (A - 1e-16): # Hinders TC, but fixes issues with floats x /= A inst = B else: inst += 1 inst = 0 while inst < len(prgm): divmeq(prgm[inst][0], prgm[inst][1]) print(x, end=" ")
This interpreter uses the symbol eof
to mark the end of a program.
Any subsequent parameters after A and B are ignored, allowing for comments. This interpreter also prints the value of the accumulator after every instruction for ease of programming.