daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Jan 29th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from random import randint
  2.  
  3. graph = {
  4.     0: [1, 7],
  5.     1: [0, 2],
  6.     2: [1, 3, 4],
  7.     3: [2],
  8.     4: [2],
  9.     5: [6],
  10.     6: [7, 5],
  11.     7: [0, 8, 6],
  12.     8: [7],
  13. }
  14.  
  15. visited = []
  16.  
  17. ci = randint(0, 9)
  18. c = graph[ci]
  19. print("Walk starts from node", ci)
  20.  
  21. moves = 0
  22. path = []
  23. while True:
  24.     if ci not in visited:
  25.         visited.append(ci)
  26.         print("Found node:", ci)
  27.     path.append(ci)
  28.  
  29.     ci = graph[ci][randint(0, len(graph[ci])-1)]
  30.     moves += 1
  31.  
  32.     if len(visited) == len(graph):
  33.         break
  34.  
  35. print("Graph explored in", moves, "steps")
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top