fork download
  1. import sys
  2. def main():
  3. s = '+++++++++++[>++++++++++<-]>++.-.+++++++.<++++[>----<-]>-.+++++++++++++.++.+++++.'
  4. mem = [0]*256
  5. stack = []
  6. i = 0
  7. j = 0
  8. while i < len(s):
  9. c = s[i]
  10. if c == '>':
  11. j += 1
  12. elif c == '<':
  13. j -= 1
  14. elif c == '+':
  15. mem[j] += 1
  16. elif c == '-':
  17. mem[j] -= 1
  18. elif c == '.':
  19. sys.stdout.write(chr(mem[j]))
  20. elif c == '[':
  21. if mem[j] == 0:
  22. while not s[i] == ']':
  23. i += 1
  24. else:
  25. stack.append(i)
  26. elif c == ']':
  27. if mem[j] == 0:
  28. stack.pop()
  29. else:
  30. i = stack[-1]
  31. i += 1
  32. if __name__ == '__main__':
  33. main()
Success #stdin #stdout 0.01s 7728KB
stdin
Standard input is empty
stdout
poverty