import sys instructions = [] for line in open(sys.argv[1]).readlines(): x = line.find('#') if x >= 0: line = line[:x] line = filter(lambda x:x!='',line.strip().split(' ')) if line: if len(line) == 1: line.append(1) else: line[1] = int(line[1]) instructions.append(line) m,k,i=[0]*2000,0,0 gotos = [None] * len(instructions) while i < len(instructions): if gotos[i] != None: i = gotos[i] c = instructions[i] i += 1 if c[0] == '+': k = (k+c[1]) % len(m) elif c[0] == '>': m[k] = (m[k]+c[1])%2000 if m[k] > 1000: m[k] = m[k]-2000 elif c[0] == '[': if not m[k]: gotos[i+c[1]] = None i = (i+c[1]) % len(instructions) else: gotos[i+c[1]] = i-1 print "Cells from 0..10 read:", m[:10]