Created
February 9, 2012 19:38
-
-
Save joelhelbling/1782312 to your computer and use it in GitHub Desktop.
Cheap Gas Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= Cheap Gas Calculator = | |
_Is it cheaper to drive across town for cheaper gas prices?_ | |
== Givens / Assumptions == | |
* Given: a particular car with its | |
** hwy MPG, | |
** tank size and | |
** current amount of fuel in gallons | |
* Given: a set of available gas stations with their | |
** distances and | |
** prices per gallon | |
* Assume: the time spent getting gas is not a consideration | |
* Assume: the driver and all stations are located along the same stretch | |
of straight highway | |
* Assume: he best solution may involve going to multiple stations | |
* Assume: road trip! Problem is solved as soon as the tank is full | |
Objective: write a calculator which returns a list of gas stations with | |
quantity purchased at each, for cheapest gas. | |
You could, *for instance*, setup something like this: | |
{ "Shecelle C. Shell" => [2, 0.00], | |
"Fissile Phillips Filling Station" => [7, 10.00], | |
"E Friendly St. BP" => [12, 10.00], | |
"Olig's OPEC and Overpriced Emporium" => [23, 10.00] } | |
then pass this: | |
{ :mpg => 2, | |
:tank_size => 25, | |
:in_tank => 10 } | |
And get this: | |
[ | |
["Shecelle C. Shell", 16] | |
] | |
== Problem Data == | |
You have a monster truck with a 25 gallon tank which gets 2 mpg | |
Here are some stations and their distances: | |
| Name | Distance | | |
| Shecelle C. Shell | 2 miles | | |
| Fissile Phillips Filling Station | 7 miles | | |
| E Friendly St. BP | 12 miles | | |
| Olig's OPEC and Overpriced Emporium | 23 miles | | |
== Some possible starting scenarios: | |
given you've got 2 gallons in the tank | |
and the shell station has free gas | |
given you've got a hypercar which gets 1 mpg | |
given 23 gallons in the tank | |
and Olig's has free gas | |
and everybody else is charging $100/gallon | |
New Requirement! (for extra credit): | |
* Rental Agency: after getting gas, drive always returns to point of origin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment