6 kyu

Which Gas Station should I pick?

95 of 204zruF
Description
Loading description...
Mathematics
Fundamentals
  • Please sign in or sign up to leave a comment.
  • ahmet_popaj Avatar

    Quite a tricky kata to understand.

  • Jadach1 Avatar

    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.

  • hobovsky Avatar

    Description should use Markdown instead of HTML.

  • Sayali-pingle Avatar

    This comment has been hidden.

  • FArekkusu Avatar

    Fixed tests should not depend on the reference solution.

  • FArekkusu Avatar

    The user can modify the input.

  • user9644768 Avatar

    Please use new python test framework.

  • GlizzyGlizzwald Avatar

    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.

  • zaozi-hinsao Avatar

    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...

  • Ching Ching Avatar

    I suggest deleting "The way back home should also be considered :)" to remove confusion because:

    1. The statement doesn't state that the driver starts from home. Neither does it state where "home" is.
    2. The cost of purchasing the fuel has already included the cost of actual fuel consumed during the journeys after the purchase.
  • yiorgos1973 Avatar

    I have no idea what is wrong. I am stucked at test 11. (Python 3)

  • MucusCrib Avatar

    This comment has been hidden.

  • yiorgos1973 Avatar

    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.

  • user7856383 Avatar

    Change name of function to gasStation or to gasstation in tests.

  • Voile Avatar

    The description is still not clear:

    var obj = {
                "gas_station1": {"price": 1.5, "distance": 50},
                "gas_station2": {"price": 2.0, "distance": 75}
              };
    var currentFuel = 35;
    var fuelConsumption = 7.5;
    
    costs gas_station1 = 48.75; <- is cheaper
    costs gas_station2 = 72.5;
    

    Why is the price for gas1 and gas2 48.75 and 72.5? Shouldn't it be 43.125 and 61.25?

  • Blind4Basics Avatar

    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...?):

    remaining: 41, consumption: 8.0
    ('iFuel', {'price': 3.0, 'distance': 7})
    ('TheStation', {'price': 2.0, 'distance': 77})
    ('Gasoline', {'price': 2.0, 'distance': 101})
    'TheStation': 50.32$
    'Gasoline':   54.16$
    'iFuel':      58.68$
    => 'TheStation' should equal 'iFuel'
    
  • FrankK Avatar

    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().

  • zruF Avatar

    Python translation added!

  • docgunthrop Avatar

    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:

    costs gas_station1 = 54.375; <- is cheaper
    costs gas_station2 = 83.75;
    

    The values should be updated to the correct values of:

    costs gas_station1 = 48.75; <- is cheaper
    costs gas_station2 = 72.5;
    
  • myjinxin2015 Avatar

    An interesting edge case to you:

    var obj = {
                "gas1": {"price": 0.1, "distance": 1000},
                "gas2": {"price": 200.0, "distance": 1}
              };
    var currentFuel = 50;
    var fuelConsumption = 2;
    
    Test.describe("Example Tests", function(){
      Test.it("Exampletest 1", function(){
        Test.assertEquals(gasStation(obj, currentFuel, fuelConsumption), "gas2");
      })
    });
    

    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 ^_^

  • myjinxin2015 Avatar

    Perhaps something is wrong(JS version): -- The funciton name in the example testcase is gasstation(wrong), but in the full tests is gasStation(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 ;-)

  • smile67 Avatar

    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;-)?