Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. from random import randint
  2.  
  3. class Point :
  4.  
  5.     def __init__(self):
  6.         self.unvisited = True
  7.        
  8.     def visit(self):
  9.         self.unvisited = False
  10.        
  11.  
  12. class Visitor :
  13.  
  14.     def __init__(self):
  15.         self.visited = []
  16.        
  17.     def goto(self, p):
  18.         p.visit()
  19.         self.visited += [p]
  20.  
  21. #For einar theory
  22. k_distribution = [0 for _ in range(6)]
  23.  
  24. case_number = 100000
  25. for case in range(case_number):    
  26.  
  27.     #m = randint(1,100)
  28.     #n = randint(1,100)
  29.     m=6
  30.     n=5
  31.    
  32.     points = []
  33.     for point in range(m):
  34.         points+=[Point()]
  35.  
  36.     visitors = []
  37.     for visitor in range(n):
  38.         visitors+=[Visitor()]
  39.        
  40.     k = 0
  41.     while any([p.unvisited for p in points]):
  42.         k+=1
  43.         for visitor in visitors :
  44.             next = points[randint(0,m-1)]
  45.             while next in visitor.visited:
  46.                 next = points[randint(0,m-1)]
  47.             visitor.goto(next)
  48.        
  49.     #print("{},{},{}".format(m,n,k))
  50.     k_distribution[k-1]+=1
  51.  
  52. print("Number of cases : {}".format(case_number))
  53. for i in range(6) :
  54.         print("k={}, frequence={}".format(i+1,k_distribution[i]/case_number))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement