``````

In :

from ipythonblocks import BlockGrid as bg
from IPython.html.widgets import interact, interactive, fixed
from IPython.html import widgets
import random
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
from IPython.display import Image

``````
``````

:0: FutureWarning: IPython widgets are experimental and may change in the future.

``````
``````

In :

def array_city(x, p1, p2):
p0 = 1-(p1+p2)
p1 = 1-(p0+p2)
p2 = 1-(p0+p1)
grid = (np.random.choice([0, 1 , 2], size = (x, x), p = [p0, p1, p2]))
return grid

``````
``````

In :

def visualize(grid):
g = bg(grid.shape, grid.shape)
for row in range(g.height):
for col in range(g.width):
block = g[row,col]
if grid[row,col] == 0:
block.blue = 1000
block.red = 1000
block.green = 1000
if grid[row,col] == 1:
block.blue = 2000
block.red = 0
block.green = 0
if grid[row,col] == 2:
block.red = 2000
block.green = 0
block.blue = 0
return g

``````
``````

In :

def visualize_big(grid):
g = bg(grid.shape, grid.shape,block_size = 5)
for row in range(g.height):
for col in range(g.width):
block = g[row,col]
if grid[row,col] == 0:
block.blue = 1000
block.red = 1000
block.green = 1000
if grid[row,col] == 1:
block.blue = 2000
block.red = 0
block.green = 0
if grid[row,col] == 2:
block.red = 2000
block.green = 0
block.blue = 0
return g

``````

### How does the amount of empty squares effect the number of loops required to reach satisfaction?

Example of high amount of empty squares

``````

In :

g = array_city(90,0.1,0.1)
visualize_big(g)

``````
``````

Out:

table.blockgrid {border: none;} .blockgrid tr {border: none;} .blockgrid td {padding: 0px;} #blockse63348b2-07b8-4cd5-bc15-0e6405a2c467 td {border: 1px solid white;}

``````

Example of low amount of empty squares

``````

In :

g = array_city(90,0.45,0.45)
visualize_big(g)

``````
``````

Out:

table.blockgrid {border: none;} .blockgrid tr {border: none;} .blockgrid td {padding: 0px;} #blocksd3f54347-4187-431d-b86c-f6cf062cfa09 td {border: 1px solid white;}</``````