<jupyter_start><jupyter_text>Painter AutomataThis is a painter automata. It follows simple rules and is completely dependent on the intial conditions.The world starts out completely white, with the painter in the middle as if it just took a step "downwards".The painter works according to these rules:* It has a palette of n colours, where every colour has a number, k, attributed to it.* When it walks over a square, the colour is changed to k + 1 (mod n).* Every colour is either a left-hand or a right-hand colour, decided by a boolean string.* If it walks over a left-hand colour, it turns left and vice versa.It works for the given number of timesteps or until it has reached the boundaries of the canvas.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import math
import matplotlib.cm as cm
import matplotlib as mpl

#Nice Patterns, given a number "bin to dec"  
#[0, 1, 0, 0, 0, 0, 1] 33
#[1, 0, 1, 1, 1, 1, 0] 94
#[0, 1, 1, 1, 1, 0, 0] 60
#[1, 1, 0, 1, 1, 1, 1] 111
#[0, 0, 1, 0, 0, 0, 0] 16
#[0, 1, 1, 1, 1, 1, 0] 62
rows = 200
columns = 200

numGraphs = 10
timesteps = 50000

colors = ['white', 'green', 'blue', 'yellow', 'brown','black', 'red']
bounds = [0,1,2,3,4,5,6]
def painter(timesteps, boolArr):
    paintBoard = np.zeros(shape=(rows, columns), dtype=int)
    startPos = math.floor(len(paintBoard)/2)
    currX = startPos
    currY = startPos

    prevX = startPos
    prevY = startPos + 1 

    countif = 0
    countelse = 0
    
    for step in range(0,timesteps):
        
        if currX is rows or currX is -1 or currY is columns or currY is -1:
            break
            
        elif boolArr[paintBoard[currX][currY]]:
            countif += 1
            paintBoard[currX][currY] += 1

            if paintBoard[currX][currY] >= len(colors):
                paintBoard[currX][currY] = 0

            xChange = currX - prevX
            yChange = currY - prevY

            if xChange is 0:
                if yChange > 0:
                    prevX = currX
                    prevY = currY
                    currX = currX + 1

                elif yChange < 0:
                    prevX = currX
                    prevY = currY
                    currX = currX -1

            elif xChange < 0:
                    prevX = currX
                    prevY = currY
                    currY = currY + 1

            elif xChange > 0:
                    prevX = currX
                    prevY = currY
                    currY = currY - 1
                    
        else:
            countelse += 1
            paintBoard[currX][currY] += 1

            if paintBoard[currX][currY] >= len(colors):
                paintBoard[currX][currY] = 0

            xChange = currX - prevX
            yChange = currY - prevY

            if xChange is 0:
                if yChange > 0:
                    prevX = currX
                    prevY = currY
                    currX = currX - 1

                if yChange < 0:
                    prevX = currX
                    prevY = currY
                    currX = currX + 1

            if xChange < 0:
                    prevX = currX
                    prevY = currY
                    currY = currY - 1


            if xChange > 0:
                    prevX = currX
                    prevY = currY
                    currY = currY + 1
                        
    return paintBoard, countif, countelse
#Feel free to try out different starting states with ownArr = 1
ownArr = 1
randArr = 0

if ownArr is 1:
    boolArr = [[0, 1, 1, 1, 0, 0, 0],
               [1, 1, 1, 1, 1, 0, 1],
               [0, 1, 0, 0, 0, 0, 1], 
               [1, 0, 1, 1, 1, 1, 0], 
               [0, 1, 1, 1, 1, 0, 0], 
               [1, 1, 0, 1, 1, 1, 1],
               [0, 0, 1, 0, 0, 0, 0],
               [0, 1, 1, 1, 1, 1, 0]]

if randArr is 1:
    boolArr = []
    for i in range(0, numGraphs):
        boolArr.append(np.random.randint(2, size=7))

for graph in range(0,len(boolArr)):
    
    print(boolArr[graph])
    
    paintBoard, countif, countelse = painter(timesteps, boolArr[graph])
    print("Right turns taken: %d, left turns taken: %d" % (countif,countelse))

    cmap = mpl.colors.ListedColormap(colors)
    norm = mpl.colors.BoundaryNorm(bounds, cmap.N)

    plt.imshow(paintBoard, interpolation='nearest', cmap=cmap, norm=norm)
    plt.show()<jupyter_output>[0, 1, 1, 1, 0, 0, 0]
Right turns taken: 22695, left turns taken: 27305
{'fraction_non_alphanumeric': 0.09923835125448029, 'fraction_numerical': 0.04233870967741935, 'mean_word_length': 1.5675675675675675, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '234633', 'license': 'MIT', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1421, 'n_words': 513, 'path': 'painter.ipynb', 'repo_name': 'LoweLundin/Miscellaneous', 'size': '4464'}