# Write a function: # # random_walk( # trans_probs, # a list of transition probabilities between each state in a directed graph (see example below) # start_state, # the state to start the walk from # num_steps, # the number of steps in the random walk to simulate # ) # # that returns a map from states to the number of times that state was visited
Sigiloso
Just traverse through each node (iter or recur) while calculating which node is next. To find which node is next, get a rand num between 0-1 then go though subtract each neighbors' probability from the rand num. When rand num <= 0 that's the next node.