To plot a 2D self-avoiding random walk in python, we can use the following code:
main.py816 chars26 linesIn this code, we first define a function called self_avoiding_RW that generates a 2D self-avoiding random walk of n steps. The function uses a while loop to generate a new position that is not already occupied by a previously generated position.
We then call self_avoiding_RW to generate a self-avoiding random walk of 100 steps and save the positions to positions. Finally, we plot the walk using plt.plot.
gistlibby LogSnag