Initially | S = [2^n, 2^(n-1), ..., 4, 2, 1, 2] | n+2 elements in the list |
After 1 application of lines 1-2: | S = [2^n, 2^(n-1), ..., 4, 2, 3] | n+1 elements in the list |
After 2 applications of lines
1-2: |
S = [2^n, 2^(n-1), ..., 4, 5] | n elements in the list |
... |
||
After n+1 applications of lines
1-2: |
S = [2^(n+1) + 1] | 1 element in the list |
transform
function in transform.py
using the Stack
class (already provided in transform.py).
class PizzaOrder:
"""
A pizza order that can be made during the pizza shop
simulation
"""
def __init__(self, id, order_time, delivery_time):
"""
Create a new PizzaOrder
based on:
id: the unique ID for the
order
order_time: the number of
minutes after the beginning of the
simulation when the order is made
delivery_time: the number of
minutes it takes to deliver pizza to
its destination
"""
self.id = id
self.order_time = order_time
self.delivery_time =
delivery_time
def simulate(cook_time, num_deliverators, orders):
"""
Simulate a pizza shop, given:
cook_time: number of minutes it takes to cook a pizza
num_deliverators: number of deliverators employed by
shop
orders: a list of pizza orders
Returns a dictionary that maps order ID to a list of
2 elements: the
first element is the ID of the deliverator who
delivered the pizza,
and the second element is the number of minutes
after the start of
the simulation when the pizza got delivered.
"""