Ad
  • Default User Avatar

    Thanks!

  • Default User Avatar

    Thank you. Your description really clarified the question for me.

  • Default User Avatar

    The description says:

    Furthermore the percent of loss increases by a fixed 0.5 percent at the end of every two months.

    Example of percents lost per month:

    If, for example, at the end of first month the percent of loss is 1, end of second month percent of loss is 1.5, end of third month still 1.5, end of 4th month 2 and so on ...

  • Custom User Avatar

    Thank you! Passed it once I understood that the depreciation is supposed to increase by 0.5% every other month.

  • Custom User Avatar

    Improved description:

    The first test case represents this situation: A man has an old car worth $2000. He is planning to buy a new car worth $8000. He needs a car, so while he saves up for the new car, he cannot get rid of his old car. He thinks he can save $1000 each month. He will use his savings plus the value of his old car to buy the new car.

    The major complication is the value of both cars is decreasing (i.e. depreciating). They both decrease by the same percent per month, 1.5% for our first test. Additionally, the amount of depreciation increases by 0.5 percent every second month.

    For each test: the price of the old car, the price of the new car, the amount saved per month, and the percentage of depreciation.

    Can you help him? Our man finds it difficult to make all these calculations.

    How many months will it take him to save up enough money to buy the car he wants, and how much money will he have left over?

    Parameters and return of function:

    parameter (positive int, guaranteed) startPriceOld (Old car price)
    parameter (positive int, guaranteed) startPriceNew (New car price)
    parameter (positive int, guaranteed) savingperMonth
    parameter (positive float, guaranteed) percentLossByMonth

    return (int array) [ months elapsed, money left over]

    nbMonths(2000, 8000, 1000, 1.5) should return [6, 766]

    Where 6 is the number of months at the end of which he can buy the new car and 766 is the nearest integer to '766.16....'

    Example of depreciation per month:

    If the starting depreciation is 1%, then the end of the first month is clearly 1%. This means the end of second month percent of loss is 1.5%. Next, the end of third month holds at 1.5%, and the end of 4th month is 2%, and so on....

    Note: Calculations are processed at the end of each month. When the value of the old car (plus savings, as necessary) is greater than the new car, the purchase will be made immediately. This means if the old car is more valuable than the new car, the new car must be purchased before any savings or depreciation occur. Values of both cars, modified by the percent of depreciation, need to be floating point values within the function. Only the final return values should be rounded off to an int.

  • Custom User Avatar

    Yup. The number of bricks visible for an empty string is 0, not -1. One shouldn't have to set up counter-intuitive catches just to match arbitrary tests. Those tests, and this kata, are essentially broken.

  • Default User Avatar

    It would be helpful for the clarity of the kata if the precise measurement / conversion of light year was given - or at least a link to the Wikipedia page showing the number of metres, to save people calculating it for themselves and failing the tests.

  • Custom User Avatar

    Interesting. I didn't know that. Removed the headings. :)

  • Custom User Avatar

    Look at the definition tab.

  • Custom User Avatar

    I'm giving myself a headache trying to find the math for part 2. The basis for the math might be physics, but it's definitely math, and as far as I'm concerned, a major issue! (not that a tag would enlighten me on the math required, but to figure it out I need a refresher on calculus, not physics)

  • Custom User Avatar

    I've been there. That's exactly why I asked.

    The first answer there is "about 9 trillion kilometres" and another is (on the right) "Unit conversions: 1 ly is equal to 9.4607×1015 m".

    But you want the exact IAU definition number.

  • Custom User Avatar

    If you remove the headings above the example blocks, CodeWars will only show the example for the currently selected language. But the codeblocks have to be contiguous.

    The language tags on the blocks are already correct. You can preview this in the kata editor (select the language bottom left above the code window.)

  • Custom User Avatar

    Are you using JS? That is fixed now.

  • Custom User Avatar

    Try looking at the light year Wikipedia page. The conversion factor can be found there.

  • Custom User Avatar

    You have got to be kidding me.

    Test Results:
    Log
    meters = 1
    ✘ Expected: '1', instead got: '2.173913043478261e-16'
    Log
    meters = 7237458811524312000
    ✘ Expected: '765', instead got: '1573.3606112009375'
    Random Tests:
    Log
    meters = 1.003e+27
    ✘ Expected: 106017183653, instead got: 218043478260.86957
    Log
    meters = 1.003e+27
    ✘ Expected: 106017183653, instead got: 218043478260.86957
    

    (This is JavaScript, BTW.)

  • Loading more items...