Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- field=[[[1,0,1,0,1],[0,1,0,0,0],[0,0,0,1,0],[0,1,1,1,0],[1,1,1,0,1],0]] #input: 1==bug
- #field=[[[0,0,0,0,1],[1,0,0,1,0],[1,0,0,1,1],[0,0,1,0,0],[1,0,0,0,0],0]] #test data
- t=0
- while t<200:
- t+=1
- if t%2: #every odd tick is first time bugs can go out a layer
- field.reverse()
- field.append([[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],-t//2]) #add a new outer layer to the front...
- field.reverse()
- field.append([[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],t//2+1]) #and a new inner one to the back
- new=[] #start empty for next iteration
- for l in range(len(field)):
- new.append([[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],l-len(field)//2]) #add a blank field
- #print(new)
- for i in range(5):
- for j in range(5):
- if i==2 and j==2: #center square! DON'T DO THIS
- continue
- lcount=field[l][i][j] #start with the value of the field
- lcount+=int(i!=0 and field[l][i-1][j]) #square left (NOT LEFTMOST COLUMN)
- lcount+=int(j!=0 and field[l][i][j-1]) #square up (NOT TOPMOST ROW)
- lcount+=int(i!=4 and field[l][i+1][j]) #square right (NOT RIGHTMOST ROW)
- lcount+=int(j!=4 and field[l][i][j+1]) #square down (NOT BOTTOMMOST ROW)
- if i==0 and l!=0: #for the leftmost column...
- lcount+=field[l-1][1][2] #go up a level and look at the square left of center
- if i==4 and l!=0: #repeat for rightmost...
- lcount+=field[l-1][3][2]
- if j==0 and l!=0: #topmost...
- lcount+=field[l-1][2][1]
- if j==4 and l!=0: #and bottommost.
- lcount+=field[l-1][2][3]
- if i==1 and j==2 and (l!=len(field)-1): #for the square left of center...
- lcount+=(field[l+1][0][0]+field[l+1][0][1]+field[l+1][0][2]+field[l+1][0][3]+field[l+1][0][4]) #go down a level and look at the leftmost column
- if i==3 and j==2 and (l!=len(field)-1): #repeat for right of center...
- lcount+=(field[l+1][4][0]+field[l+1][4][1]+field[l+1][4][2]+field[l+1][4][3]+field[l+1][4][4])
- if i==2 and j==1 and (l!=len(field)-1): #above center...
- lcount+=(field[l+1][0][0]+field[l+1][1][0]+field[l+1][2][0]+field[l+1][3][0]+field[l+1][4][0])
- if i==2 and j==3 and (l!=len(field)-1): #and below center
- lcount+=(field[l+1][0][4]+field[l+1][1][4]+field[l+1][2][4]+field[l+1][3][4]+field[l+1][4][4])
- if lcount==2: #if two total spaces have bugs, including the original square...
- new[l][i][j]=1 #the square has bugs!!! yay!!!
- if (lcount==1 and field[l][i][j]==0): #but if the square didn't have bugs before, and this total is one...
- new[l][i][j]=1 #still has bugs!!!
- field=new #update the whole field
- print(t)
- bcount=0 #start with no bugs
- for l in range(len(field)): #and just...
- for i in range(5): #loop over...
- for j in range(5): #everything
- bcount+=field[l][i][j]
- print(bcount) #0ω0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement