''' The ant starts on a white grid. On a white cell, it turns right, changes the cell color to black, and moves forward On a black cell, it turns left, changes the cell color to blue, and moves forward On a blue cell, it turns up, changes the cell color to yellow, and moves forward On a yellow cell, it turns down, changes the cell color to white, and moves forward ''' dim = 100 #20 works for 1000 grid = [[[0 for i in range(dim)] for j in range(dim)] for k in range(dim)] black, blue, yellow, total = 0, 0, 0, 0 antpos = [dim//2,dim//2,dim//2] antfr, antrt, antup = [1,0,0],[0,1,0],[0,0,1] s = "" for n in range(94176): ..if antpos == [dim//2,dim//2,dim//2]: print(n) ..if dim-1 in antpos or 0 in antpos: ....print(n,"Grid too small!") ....break ..if grid[antpos[0]][antpos[1]][antpos[2]] == 0: #turn ant and adjust cell counts ....antfr, antrt = antrt, [-i for i in antfr] ....black, total = black+1, total+1 ..elif grid[antpos[0]][antpos[1]][antpos[2]] == 1: ....antfr, antrt = [-i for i in antrt], antfr ....black, blue = black-1, blue+1 ..elif grid[antpos[0]][antpos[1]][antpos[2]] == 2: ....antfr, antup = antup, [-i for i in antfr] ....blue, yellow = blue-1, yellow+1 ..elif grid[antpos[0]][antpos[1]][antpos[2]] == 3: ....antfr, antup = [-i for i in antup], antfr ....yellow, total = yellow-1, total-1 ..grid[antpos[0]][antpos[1]][antpos[2]] += 1 #recolor cell ..grid[antpos[0]][antpos[1]][antpos[2]] %= 4 ..antpos = [i+j for i,j in zip(antpos,antfr)] ..''' ..following lines print a 1400-generation window centered on the formation .. of the highway to show periodicity; they can be deleted if desired ..''' ..if n >= 92775: ....s += str((3*antfr[0]+2*antfr[1]+antfr[2])%7) ....if len(s) == 28: ......print(s) ......s = ""