6 kyu
Which Gas Station should I pick?
95 of 204zruF
Loading description...
Mathematics
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Quite a tricky kata to understand.
Not rational and likely to cause headaches.
It takes into account for total cost, the fuel you consume travelling to and from said station; This is why the original examples price is 48.75, it is the price 1.5 * the total in litres 32.5. You will be filling the original 60 - 35 = 25 litres, plus the trip to and from which are each 3.75 litres. Based on Fuel Consumption 7.5/100 * distance.
But, it doesn't take into account total fuel you will have upon returning to your home. So, my original solution checked to make sure that if you LEAVE to get fuel you will return home with MORE fuel than when you left. Some test cases had me returning home with less fuel, why would i leave home and waste money to have less fuel.
I understand it is for fun, but more concise explanation or description would help understand the goal of the function. So, it is not a practical or realistic test and should reflect better parameters in the description.
not reading allat
I agree that it would be more sensible? fun? realistic? to take into account how much you fuel level has actually increased by the time you got home. But it's a 7 year old kata, it's not changing.
Description should use Markdown instead of HTML.
This comment has been hidden.
not an issue with the kata
Fixed tests should not depend on the reference solution.
The user can modify the input.
Please use new python test framework.
Done.
I could never imagine travelling 50km for a tank of gas but I also couldnt imagine travelling 50m even more. I think the distance's measurement should be made clear in the description.
I'm confused, so you were not going gas station to refuel, you were going gas station to buy the gas, then refuel when you get back home, or you refuel at gas station but buy extra ?? It's quite disturbing...
I suggest deleting "The way back home should also be considered :)" to remove confusion because:
I have no idea what is wrong. I am stucked at test 11. (Python 3)
This comment has been hidden.
I tried changing it to multiply distance by 2 (in order to account for the way back) but then it fails even more of the tests!
You did not consider the way back home in the price and you also calculate the price of a full tank when distance is 0. What if distance is 0 but there is still gas in the tank? ;-)
Wow thank you. I have no idea how but it works now!
Hi I would like to try that but I can't understand how to use Fuel Consumption . Consumption to what ? To distance ? give an example please of what it means.
#fuelConsumption: how much your car consum in l/100km <- from the description ;-)
Change name of function to gasStation or to gasstation in tests.
I don't understand your suggestion. The function is defined as "gasStation" in the tests, isn't it?
the name of the function is not CamelCase ... function gasstation(obj, currentFuel, fuelConsumption){}
Tests check on gasStation!!
Ah, well okay! I fixed the initial solution. Thanks! :)
The description is still not clear:
Why is the price for
gas1
andgas2
48.75 and 72.5? Shouldn't it be 43.125 and 61.25?How did you calculated it?
I calculated the remaining fuel the car would have when it reached each station, then fill the tank until it has 60L.
@Voile: read the description again, you missed one tiny part of the specs. ;)
@Voile, you are more or less right. You can only fill gas which is consumed on the way to each station, but not the gas when you are on the way back home. Nevertheless the way back home has to be considered, because it has an impact on the cost.
Oh, so that's what I was missing. Kata done!
(See, that's why the description really need some rework.)
Hi,
Some troubles with python version:
in the description, the code block if JS-like instead of python code
either you have to specify the rule when ties are presents, or you should make those ties illegal in the random tests.
especially, equivalent stations show up in the random tests:
remaining: 50, consumption: 10.0 ('Powerfuel', {'distance': 19, 'price': 3.0}) <= ('TheStation', {'distance': 113, 'price': 2.0}) ('FillMeUp', {'distance': 19, 'price': 3.0}) <= ('Gasoline', {'distance': 98, 'price': 3.0})
Errrr... Seems there are some other problems in the random tests (I don't see what I could have done wrong, but maybe I did anyway...?):
Hi Blind4Basics, thanks for your feedback! I will take care about a python example in the description.
I didn't though about ties, yet, but i also will take care of it.
Can you provide me your sourcecode? I guess my solution in the random tests is correct. Did you also calculate the fuel cost for the distance back home?
For your example i get the following costs:
This comment has been hidden.
Yup, you didn't calculate the way back home ;-)
damn, I didn't see that. Maybe you should regroup the informations in the description?
Ok, i updated the description. And I don't see the nessecity to provide a python example in the description because the object in python is pretty much the same as the example in JS ;-) BTW: I prevent ties of different objects in the random testcases. So i guess the issue can be closed ;)
yep, all good! (I just do not fully agree about the JS-like part of the python description, but... well, this is just a matter of details, yes. ;) )
That was a quest for the correct formula... :) I was the first to start and then the description was not yet as good as it is now.
At first I was puzzled: are these gas stations on the road ahead? No, you just drive back and forth.
I think a more correct formula would be: 'total amount payed' / 'net fuel gain' instead of the 'total amount payed' / 'current fuel'.
By accident, I submitted a sloppy working version. My solution is not on every submit 'green' and I was still testing this with a lot of console.log().
Python translation added!
It appears that, after correcting the issues brought up by others who completed this kata, the example in the description was not updated to reflect said corrections. This may likely be a source of confusion for users who are comparing their output using the example values.
In the example:
The values should be updated to the correct values of:
Updated the description. Thanks! :)
An interesting edge case to you:
Yes,
gas1
is so cheap ;-) But when you go back, you'll find that you have only 40 litres of fuel, But you have 50 litres in the beginning^_^
And therefore I set the parameter in a specific range^^
Perhaps something is wrong(JS version): -- The funciton name in the example testcase is
gasstation
(wrong), but in the full tests isgasStation
(right)-- The calculation method is very strange, your solution to calculate the fuel consumption three times. When you go back, the money of fuel is actually already paid to the gas station. I'm not sure, but I think so ;-)
-Fixed the name in the example tests. -Oh well, you're right. I changed the calculation to two times the fuel consumption ;) Thank's Lord Jinxin ;)
What about the price of my actual tank before i reach the gas station? Maybe it differs from the new price, so how to calculate the distance to the station;-)?
I knew this question will come :D To simplify this: just calculate it with the current price of the gas station ;)
edit: I put an info in the description
Thanks for your response;-)! There's place for more "stupid questions", but now i prefered to solve it:-)...