Skip to content

Instantly share code, notes, and snippets.

@hornc
Last active September 9, 2022 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hornc/ea8711a5803986a855a0d755c2e08092 to your computer and use it in GitHub Desktop.
Save hornc/ea8711a5803986a855a0d755c2e08092 to your computer and use it in GitHub Desktop.
"""
Python Portable Minsky Machine
Implements a Python version of
https://esolangs.org/wiki/Portable_Minsky_Machine_Notation
"""
counters = {}
def inc(counter):
counters[counter] = counters.get(counter, 0) + 1
def dec(counter):
test = bool(counters[counter])
counters[counter] = max(0, counters.get(counter, 0) - 1)
return test
## Syntactic sugar
def inc_by(counter, amount):
counters[counter] = counters.get(counter, 0) + amount
def dec_by(counter, amount):
test = bool(counters[counter])
counters[counter] = max(0, counters.get(counter, 0) - amount)
return test
## I/O Extenstion
def input(counter):
pass
def output(counter):
if dec(counter):
print(chr(counters[counter]))
counters[counter] = 0
## Helper methods, not part of the original spec:
def show():
"""Shows all set registers."""
print("Counter Value")
for k,v in counters.items():
print(k, v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment