Skip to content

Instantly share code, notes, and snippets.

@justecorruptio
Last active June 24, 2020 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save justecorruptio/ecaba65cce39e96f614a to your computer and use it in GitHub Desktop.
Save justecorruptio/ecaba65cce39e96f614a to your computer and use it in GitHub Desktop.
Tiny brainfuck interpreter.
import sys,os;M=[0]*30000;A=[]
p=k=x=0;S=open(sys.argv[1]).read()
while x<len(S):exec"""M[p]+=1
M[p]-=1 M[p]=ord(os.read(0,1)or"\\0")
os.write(1,chr(M[p])) p-=p>0 p+=1
k=A.append(x)if+M[p]else+1 x=A.pop()-1
k+=1 0 k-=1 0""".split()['+-,.<>[][+]+'
.find(S[x]+'+'*(k>0))];M[p]&=255;x+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment