Skip to content

Instantly share code, notes, and snippets.

Last active December 18, 2020 09:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import random
# Set the following arguments
noSimulations = 100000
# The following graph is saved in the dictionary "graph"
# A--B--C--D
# | | | |
# E--F--G--H
# | | | |
# I--J--K--L
# A player moves from A to L by randomly choosing a path, moving only from top to bottom or left to right.
graph = {"a": ("b", "e"), "b": ("c", "f"), "c": ("d", "g"), "d": ("h"), "e": (
"f", "i"), "f": ("j", "g"), "g": ("h", "k"), "h": ("l"), "i": ("j"), "j": ("k"), "k": ("l")}
def moveThroughGraph():
startNode = "a"
currentNode = startNode
nodesVisited = []
for i in range(0, 5):
currentNode = random.choice(graph[currentNode])
return nodesVisited
def getSimulations():
allSimulations = []
for i in range(noSimulations):
return allSimulations
def evaluateSimulations(simulationList):
count = 0
for simulation in simulationList:
if observerAt in simulation:
count += 1
return count
if __name__ == "__main__":
for observerAt in ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"]:
observerAtSpecifiedPointCount = evaluateSimulations(getSimulations())
print("The observer has been seen %d out of %d times at point %s. He was observerd with a probability of %s"
% (observerAtSpecifiedPointCount, noSimulations, observerAt, "{0:.0%}".format(float(observerAtSpecifiedPointCount)/float(noSimulations))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment