Skip to content

Instantly share code, notes, and snippets.

@humachine
Created September 15, 2014 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humachine/8402f2183d126a8eb486 to your computer and use it in GitHub Desktop.
Save humachine/8402f2183d126a8eb486 to your computer and use it in GitHub Desktop.
Ant_Prob
import sys
import numpy as np
prev=np.zeros((7,7))
now=np.zeros((7,7))
prev[3,3]=1
N=15
for i in range(N):
# print prev
for x in range(1,6):
for y in range(1,6):
now[x,y]=0.2*(prev[x-1, y] + prev[x+1, y] + prev[x,y-1] + prev[x,y] + prev[x,y+1])
# print x,y, prev[x-1, y] ,prev[x+1, y],prev[x,y-1],prev[x,y],prev[x,y+1], now[x,y], prev[x,y]
for x in range(1,6):
now[1, x]+=0.2*prev[1,x]
now[5, x]+=0.2*prev[5,x]
now[x, 1]+=0.2*prev[x,1]
now[x, 5]+=0.2*prev[x,5]
some=1*prev
prev[:]=now
print now[3,3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment