forked from calthoff/goselftaught
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation.py
38 lines (28 loc) · 822 Bytes
/
simulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import time
import random
class Queue:
def __init__(self):
self.items = []
def is_empty(self):
return self.items == []
def enqueue(self, item):
self.items.insert(0, item)
def dequeue(self):
return self.items.pop()
def size(self):
return len(self.items)
def simulate_line(self, till_show, max_time):
pq = Queue()
tix_sold = []
for i in range(100):
pq.enqueue("person" + str(i))
t_end = time.time() + till_show
now = time.time()
while now < t_end and not pq.is_empty():
now = time.time()
r = random.randint(0, max_time)
time.sleep(r)
person = pq.dequeue()
print(person)
tix_sold.append(person)
return tix_sold