Last active
July 16, 2019 13:59
-
-
Save bahorn/ee6f5c2fdb176445d8b685665735c1b0 to your computer and use it in GitHub Desktop.
a One Instruction Programming language made up of only 10x and newlines. so you can claim to be a 10x developer...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
# returns the next instruction to run | |
def oisc(ip, m): | |
m[m[ip+1]] = (m.get(m[ip+1], 0) - m.get(m[ip+0], 0)) & 0xFFFFFFFF | |
if m[m[ip+1]] > 0x7FFFFFFF or m[m[ip+1]] == 0: | |
return m[ip+2] | |
else: | |
return ip+3 | |
memory = {} | |
with open(sys.argv[1]) as code: | |
for line in code.read().split(): | |
m, a, b, c = map( | |
lambda o: int(o, 2), | |
line.split('x') | |
) | |
# Place the code in memory | |
memory[m+0] = a | |
memory[m+1] = b | |
memory[m+2] = c | |
ip = 0 | |
while True: | |
try: | |
ip = oisc(ip, memory) | |
except KeyError: | |
break | |
# Display the state after execution | |
for key in memory: | |
a = key | |
v = memory[key] | |
print("{:0>32b}: {:0>32b}".format(a, v)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment