Skip to content

Instantly share code, notes, and snippets.

@umnikos
Last active January 13, 2022 12:35
Show Gist options
  • Save umnikos/5e4cd79872af7fb7a986efdcfd96f9d3 to your computer and use it in GitHub Desktop.
Save umnikos/5e4cd79872af7fb7a986efdcfd96f9d3 to your computer and use it in GitHub Desktop.
An interpreter for the Quiner esolang (more info on https://esolangs.org/wiki/Quiner)
code = input("enter quiner code: ")
data = ""
code_ip = 0
data_ip = 0
debug = False
a = 1
a_len = 0
inputs = ""
#for i in range(30):
while True:
if debug:
print("---")
print(code)
print(data)
if len(data) <= data_ip:
data_ip = len(data)
if len(code) <= code_ip:
code_ip = len(code)
if len(data) <= data_ip:
break # halt if both programs are done
else:
# switch them around if data program is not done but code program is
(code, data) = (data, code)
(code_ip, data_ip) = (data_ip, code_ip)
instruction = code[code_ip]
if instruction in "1234567890":
if debug:
print("digit")
if a_len == 0:
a = 0
a *= 10
a += int(instruction)
a_len += 1
else:
if debug:
print("instruction")
print(a)
print(a_len)
if instruction == "*":
data = data[:-a]
elif instruction == ",":
while len(inputs) < a:
inputs += input()
inputs += "\n"
data += inputs[:a]
inputs = inputs[a:]
elif instruction == ".":
print(data[-a:], end="")
data = data[:-a]
elif instruction == ">":
data += code[code_ip+1:code_ip+1+a]
code_ip += a
elif instruction == "<":
data += code[max(0,code_ip-a_len-a):code_ip-a_len]
elif instruction == "/":
if code[code_ip+1] == "/":
code_ip += a + 1
else:
code_ip += 1
elif instruction == "+":
if a_len == 0:
a = 2
chars = data[-a:]
data = data[:-a]
res = chr(sum(map(ord, chars)) % 256)
data += res
a = 1
a_len = 0
code_ip += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment