Elves for Santa

Santa and his elves are really busy preparing this year’s Christmas presents in the North Pole right now! In this problem, we will model Santa and the elves using an object oriented approach with three classes: Present, Elf, and Santa. The Santa and Present classes have already been implemented, and your task will be to implement the Elf class.

Before you start working on the Elf class, you should read the code in santa.py to familiarize yourself with our implementation. Study the Santa class carefully, as we will be using the Elf class exclusively within the Santa class. You should also study the Present class, since it may be helpful for the implementation of the Elf class. Your are free to design the Elf class however you like, using the existing Santa and Present classes (and their methods) if necessary. However, you are not allowed to modify or add any new methods to the Santa and Present classes, nor are you allowed to add any functions. Your work will be constrained exclusively to the Elf class.

Based on what Santa needs, these are the minimal requirements for the Elf class:

1. Santa needs to be able to create a new Elf object by calling Elf() as shown in the gather_elves method, without any arguments.

2. Santa needs to be able to assign a new present for an elf to make, as shown in the distribute_presents_to_make method. This is done by calling the add_present method in the Elf class. Therefore, your implementation of the Elf class must contain this method, which takes in one argument, a present (that is, an instance of the Present class). The method does not return anything.

An elf can have several presents assigned to him, but can only make one present at a time, in the same order that they were assigned to that elf (you can assume that the current_time values passed to multiple add_present calls are always in the increasing order). As soon as he is done with one present, he will move on to another immediately (if there are more presents assigned to him). Moreover, we assume that all presents take the same amount of time to make (the defined PRESENT_PRODUCTION_TIME).

3. Given the current time (a float), Santa needs to be able to collect all ready presents from an elf by calling the remove_presents method in the Elf class. This method takes in one argument (the current time), and the number of presents that the elf has made. If no presents are ready, the method should return 0. This method should have the side effect of removing all ready presents so that they are not associated with the elf any more.

Once you have implemented your Elf class, you can simulate Santa’s workshop by running:

$ python3 santa.py

This code generates a random number for the number of presents to send to each elf. You can set the seed for the random number generator by importing your code into ipython3 and the running the santa.simulate_Santa function. Here are some sample calls:

In [2]: import santa

In [3]: santa.simulate_Santa(100, 100, seed=1234)
Santa has 7237 presents ready, and 306 presents in progress!

In [4]: santa.simulate_Santa(100, 100, seed=1234)
Santa has 7237 presents ready, and 306 presents in progress!

In [5]: santa.simulate_Santa(100, 100, seed=5678)
Santa has 7630 presents ready, and 315 presents in progress!

In [6]: santa.simulate_Santa(100, 100, seed=9999)
Santa has 7560 presents ready, and 273 presents in progress!