Hot dog eating is an exciting, competitive sport in America. In a regulation hot dog eating competition, two athletes eat as many hot dogs as they can in 10 minutes. We would like to simulate the 2017 contest between the legendary Joey Chestnut and Carmen Cincotti. Although Joey Chestnut won for the 10th time, some experts believe Carmen Cincotti had greater stamina and could have won if the competition had lasted longer.
Our data scientists have modeled Joey Chestnut's and Carmen Cincotti's hot dog eating abilities with equations that predict how long it will take to eat the next hot dog, as a function of how many hot dogs have been eaten already. For example, Joey Chestnut's equation is:
e0.0344n + 4
Where n
is the number of hot dogs eaten already. If we plug in n = 0
, we see that Joey can eat his first hot dog in 5 seconds.
The data scientists would like you to simulate their models under various conditions. For each model, or test case, they would like to know when each competitor ate a whole hot dog, how many hot dogs were eaten by each competitor, and who ate the most hot dogs.
- A Python 3 environment if running the Python simulation.
- A Java 8 environment if running the Java simulation.
- A Node.js 8 environment if running the JavaScript simulation.
-
Checkout the code:
git clone https://github.com/Tignis/hotdog.git
-
Ensure that your Python and/or Java and/or Node.js environments are suitable for compiling and executing the code:
python -m unittest test.py
or
mvn clean test
or
node test.js
-
Subclass or implement a compatible Competition class or function, located in
competition.py
orCompetition.java
orcompetition.js
. -
The
run()
function should return a list of (or iterator over)Event
objects, one for each time that a competitor has eaten a whole hot dog, and one for each competitor at the end (representing their final results).[ Event(elapsed_time=5.000, name="Joey Chestnut", total_hot_dogs_eaten=1.000), Event(elapsed_time=6.000, name="Carmen Cincotti", total_hot_dogs_eaten=1.000), ... Event(elapsed_time=600.000, name="Joey Chestnut, ...), Event(elapsed_time=600.000, name="Carmen Cincotti, ...), ]
-
The list of (or iterator over)
Event
objects should be sorted byelapsed_time
(in Python) orelapsedTime
(in Java and JavaScript). If twoEvent
objects have the sameelapsed_time
, they should be further sorted byname
. -
When reporting
elapsed_time
andtotal_hot_dogs_eaten
in Event objects, fields should be rounded to 3 decimal places of precision (the newspapers do not have space). Be careful not to let limited precision affect the order of Events reported, or determine the winner of a competition. Hot dog eating competitions can be extremely close contests. -
The
winner()
function should return the name of the winner of the competition, e.g."Joey Chestnut"
. If the two competitors ate exactly the same number of hot dogs, the winner is the competitor whosename
comes first lexicographically. -
At the end of the competition, each competitor probably only ate part of their last hot dog. For the purposes of calculating how much of the last hot dog was eaten, you may assume that hot dogs are eaten at a linear rate. For example, if it takes Joey 5 seconds to eat a hot dog, he eats it a rate of 0.2 hot dogs per second.
-
Add a new unit test for the class to
test.py
orYourTest.java
ortest.js
. -
Commit your changes. Include any special instructions that might be necessary for running the code (for example, how to install any additional dependencies), in the commit message. Reply to the e-mail you received asking you to complete this exercise, and attach your patch file to the message.
git commit -am "Implemented the Competition class." git format-patch origin/master