def PofRelativelyPrime(n): l = [[False] * n for i in range(n)] for i in range(n): for j in range(n): if PofInt.relativelyPrime(i,j): l[i][j] = True percolationio.draw(l,True)
def Pofx(n): l = [[False] * n for i in range(n)] for i in range(n): for j in range(n): if odd(comb(i,j)): l[i][j] = True percolationio.draw(l,True)
def main(): n = int(sys.argv[1]) p = float(sys.argv[2]) trials = int(sys.argv[3]) for i in range(trials): isOpen = percolationio.random(n, p) stddraw.clear() stddraw.setPenColor(stddraw.BLACK) percolationio.draw(isOpen, False) stddraw.setPenColor(stddraw.BLUE) full = percolation.flow(isOpen) percolationio.draw(full, True) stddraw.show(1000.0) stddraw.show()
def leftRight(isOpen,isFull,i,j): t = j #向左一直找空的 while 1 <= t and isOpen[i][t-1]: isFull[i][t-1] = True t -= 1 percolationio.draw(isFull, True) stddraw.show(50.0) t = j #向右一直找空的 while t < n-1 and isOpen[i][t+1]: isFull[i][t+1] = True t += 1 percolationio.draw(isFull, True) stddraw.show(50.0) return isFull
def main(): # n = int(sys.argv[1]) # p = float(sys.argv[2]) # trials = int(sys.argv[3]) n = 20 p = .5 trials = 5 for i in range(trials): isOpen = percolationio.random(n, p) stddraw.clear() stddraw.setPenColor(stddraw.BLACK) stddraw.setPenRadius(0.005) percolationio.draw(isOpen, True) stddraw.setPenColor(stddraw.BLUE) stddraw.setPenRadius(0.05) full = percolation.flow(isOpen) percolationio.draw(full, True) stddraw.show(1000.0) #print('over') stddraw.show()
def flow(isOpen): n = len(isOpen) isFull = stdarray.create2D(n, n, False) stddraw.setPenColor(stddraw.BLUE) for j in range(n): isFull[0][j] = isOpen[0][j] percolationio.draw(isFull, True) stddraw.show(50.0) for i in range(1, n): for j in range(n): if isOpen[i][j] and isFull[i-1][j]: isFull[i][j] = True percolationio.draw(isFull, True) stddraw.show(50.0) # for j in range(n): # if isOpen[i][j]: # if 1 <= j and j < n-1: # if isFull[i][j-1] or isFull[i][j+1]: # isFull[i][j] = True # percolationio.draw(isFull, True) # stddraw.show(50.0) isFull = horizontal(isOpen,isFull,i) return isFull
def _flow(isOpen, isFull, i, j): n = len(isFull) if (i < 0) or (i >= n): print(i, j) return if (j < 0) or (j >= n): print(i, j) return if not isOpen[i][j]: print(i, j) return if isFull[i][j]: print(i, j) return isFull[i][j] = True stddraw.setPenColor(stddraw.BLUE) percolationio.draw(isFull, True) stddraw.show(100) global depth depth += 1 _flow(isOpen, isFull, i + 1, j) # Down. _flow(isOpen, isFull, i, j + 1) # Right. _flow(isOpen, isFull, i, j - 1) # Left. _flow(isOpen, isFull, i - 1, j) # Up.
def Pofhadamard(n): l = hadamard.had(n) percolationio.draw(l,True)