To simulate a self-avoiding random walk, we can use a simple algorithm that generates a random walk path while ensuring that the path does not cross itself. Here's a Python implementation of this algorithm:
main.py796 chars30 lines
This function takes an integer n_steps
as input, which represents the number of random moves to generate. It returns a list of positions visited by the walk.
To visualize the walk, we can use the matplotlib
library as follows:
main.py259 chars11 lines
This will generate a plot of the self-avoiding random walk path.
gistlibby LogSnag