band = {0:' '} pos = 0 n = 0 zustand = 'A' kopfbewegung = None tt = {('A',' '):('B','I','R'), ('A','I'):('C','I','L'), ('B',' '):('C','I','R'), ('B','I'):('B','I','R'), ('C',' '):('D','I','R'), ('C','I'):('E',' ','L'), ('D',' '):('A','I','L'), ('D','I'):('D','I','L'), ('E',' '):('A','I','S'), ('E','I'):('A',' ','L')} import time t1 = time.time() # print(n,band,pos,zustand) # DEBUG while kopfbewegung != 'S': n = n + 1 gelesen = band.get(pos,' ') (zustand,zuschreiben,kopfbewegung) = tt.get((zustand,gelesen),('F','F','S')) band.update({pos:zuschreiben}) if kopfbewegung == 'L': pos = pos - 1 elif kopfbewegung == 'R': pos = pos + 1 # print(n,band,pos,zustand) # DEBUG t2 = time.time() Bandinhalt = ''.join([band.get(x) for x in sorted(band)]) anz = len(Bandinhalt.replace(' ','')) print(Bandinhalt,anz,n,t2-t1) PosInhalt = pos - min(sorted(band)) Position = ' '*PosInhalt+'^'+' '*(len(Bandinhalt)-PosInhalt-1) print(Position,pos)