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

  • 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

    The description says "convert lightyears to meters" but the solution tests for converting meters to lightyears.

  • Custom User Avatar

    I almost considered highlighting that issue with:

    def countBits(n):
    return count_bits(n)

    PEP8 compliant function

    def count_bits(n):
    # actual code exercise