Codejam Qualification Round 2018. Task 3
Process Simulationxxxxxxxxxx
def go_command(i,nrows):
el=(i+1)*[.7,.5,.5]
return [[.1]*(nrows+2),
[.1]+[.3]*nrows+[.1],
[.1,.3]+el[:nrows-2]+[.5]*(nrows-5-3*i)+[.3,.1],
[.1]+[.3]*nrows+[.1],
[.1]*(nrows+2)]
def mplot(arr,i):
if i==0:
st='(0,0)'
else:
st=str((3*i-1,2))
return matrix_plot(
arr[i],figsize=(3,5),frame=False,cmap='bone',
title='(x+1,y+1)=%s'%st)
def gogo(
A=selector([36,54,72],default=54,
label='$\\color{darkorchid}{\\mathbb{A}}$')):
ti='$\\color{darkorchid}{\\mathbb{cell \\; coordinates \\;'+\
' for \\; iterations \\;=>=>=>}}$'
pretty_print(html(ti))
nrows=A//3+(A%3!=0)*1
region0=[[.1]*(nrows+2),[.1]+[.3]*nrows+[.1],
[.1,.3]+[.5]*(nrows-2)+[.3,.1],
[.1]+[.3]*nrows+[.1],[.1]*(nrows+2)]
region=[region0]
for i in range(nrows//3):
region.append(go_command(i,nrows))
animate([mplot(region,i) for i in range(1+nrows//3)]).show()
xxxxxxxxxx
import numpy as np
def random_coords(i):
idx=randint(0,8)
y=idx%3
x=i+idx//3-1
return x,y,idx
def maplot(arr,st):
m=matrix(arr.tolist())
m.subdivide([1,2],[1,2])
mp=matrix_plot(m,figsize=(3,3),cmap='bone',frame=False,
title=st,subdivisions=True,
subdivision_style=dict(color='slategray'))
return mp
goal=list(range(9))
arr=np.array(3*[3*[.1]])
mps=[maplot(arr,'[-1,-1],-1')]
c=0
while goal!=[]:
x,y,idx=random_coords(1)
st=str(([x+1,y+1],idx+1))
arr[x][y]=.3
if idx in goal:
goal.remove(idx)
mps+=[maplot(arr,st)]
c+=1
pretty_print(html('%d random (x,y)'%c))
pretty_print(html('the command (2,2) in a 3X3 target region'))
animate(mps).show()
No comments:
Post a Comment