6 kyu

Buying a car

362 of 18,068g964
Description
Loading description...
Fundamentals
Mathematics
  • Please sign in or sign up to leave a comment.
  • talonmortem Avatar

    For 5 testcase in golang i used int(math.Round(sum-priceNew)) for correct round.

  • PavloShutz Avatar

    Really frustrating when expected 954 and you got 955 :(

  • VladimirBy36 Avatar

    Add rounding up to the description (1.55 = 2)

  • Shkry_bake Avatar

    i'm getting roundings issues

  • dayfine Avatar

    Trying this in Ocaml and quickly gave up as it seems I needed to do lots of float<->int conversions.

  • SS-Stefanov1 Avatar

    JS still uses node 8, should be updated to modern versions.

  • alvaronaschez Avatar

    I honestly and respectfully think it is hard to explain the problem that bad. Don't waste your time with this kata, I did so I can advise you and complain about it.

  • choyoon88 Avatar

    The problem is not very clear.. if the price goes down by 1.5% every month, why is the example provided is not showing the 1.5% down every month? Waste of my time...

  • Fob0s96 Avatar

    Quite an interesting task, it took me 2 evenings, I realized that it is difficult for me to navigate percentages, and I need to read the task more carefully. I'm pleased with the result.

  • dondowoldo Avatar

    This comment has been hidden.

  • IRUKYEO Avatar

    i need to use malloc

  • functional programmer Avatar

    This comment has been hidden.

  • k4r1m Avatar

    This comment has been hidden.

  • trashy_incel Avatar

    C fork

    • better assertion messages
    • initial code no longer crashes
    • allocation model is explained in the initial code
    • backwards-compatible
  • 1alexvash Avatar

    savingPerMonth instead of savingperMonth

  • Bigoh20 Avatar

    Too easy for 6kyu

  • saudiGuy Avatar
  • CodeMan99 Avatar

    Really do NOT love overly math-y problem in bash. Literally the wrong tool for the job. Oh well, I got some experience with bc syntax I guess.

  • ilikechocolat Avatar

    the example code is very good and only reason I could solve the question.

  • Juancho2004gg Avatar

    This guy always have the craziest and confusing descriptions XD. This kata doesn't specify why the old car price matter

  • v1taly Avatar

    This comment has been hidden.

  • crismaver1993 Avatar

    This comment has been hidden.

  • QrersT Avatar

    I passed all of the tests instead of third(main one), it says Expected: '[0, 4000]', instead got: '[0, 3999]'. What's the problem, if my code returning 3999.1, so logigaly it must be rounded to 3999, not 4000!? Random rests passed with no issue.

  • Alexenon Avatar

    This comment has been hidden.

  • BLVCK7 Avatar

    This comment has been hidden.

  • marjan Avatar

    Accomplised in c++.

  • Matteo Zattera Avatar

    This comment has been hidden.

  • keekkenen Avatar

    its strange, but kotlin engine cannot resolve Double.roundToInt(), it since from Kotlin 1.2

  • Heeho Avatar

    Kotlin: solved with java Math.round

    Author, please, it is wrong to round money leftovers inconsistently, should be either floor or ceiling!

  • eziolise Avatar

    I was really frustratd by this kata, Math.round and Math.ceil didnt do anything for me, I would pass all the tests but fail one out of five on the attempts due to rounding error.

    log is 331 expected 332 log is 112 expected 113

    FRUSTRATING !

  • oliverlevay Avatar

    "percent of loss increases of 0.5 percent at the end of every two months" implies that the loss increases with 0.5%, i.e:

    loss = loss * 1.05 instead of loss -= 0.05

    Can this text be changed to say 0.5 percentage points instead? https://en.wikipedia.org/wiki/Percentage_point

    something like

    "percent of loss increasese with 0.5 percentage points at the end of every 2 months"

  • smile4me Avatar

    fwiw, in Perl, the use of printf("%.0f",$float) does a "round half to even" which does not work like the conventional "round to infinity" that we learned in grade school math.

    the kata could be improved to catch this case, possibly. Not sure if this matters in other languages.

    Stack Overflow for the win.

  • justinespejo Avatar

    Anyone try this with java? Test 4-6 is failing for me. It says i need 8 months but it only takes 4 months. I even hand computed it and my solution is correct.

  • MAYUBXG Avatar

    Test Passed: Value == '[0, 0]' Expected: '[6, 766]', instead got: '[6, 540]'

  • gaborio Avatar

    Good Kata!

  • jekanss Avatar

    I managed to pass 20 out of 21 tests. Is there a problem with this kata?

  • jonas_123 Avatar

    Got them all except for the last one, it's off by 1, maybe there's an issue or maybe there's a concept that I didn't know about.

  • ejini战神 Avatar
    • Node 18 (mocha + chai) should be enabled (Refer this and this for more info)

    • Ruby 3.0 should be enabled (Refer this & this for more detail)

  • ejini战神 Avatar

    function name should be snake_case in crystal and ruby at least

  • Artem22660044 Avatar

    This comment has been hidden.

  • jaspingrobus Avatar

    A lot of issues with the rounding. When doing kata like this the test should be tolerant for off by 1 errors.

  • Husoski Avatar

    This comment has been hidden.

  • jon_e Avatar

    It confused me initially since I thought the loss of value in the old cars value would equate to an increase in funds needed as apose to reduction in the total equation but I get it now. ANybody else think this way?

  • Alvinn Avatar

    This comment has been hidden.

  • B1t3r Avatar

    Hi, How can I return? What is the form? I tried the string, block with address, with value but again and again I get (0,0)... If I return "A" I get (65, 1148846080). (Of course 65 is A but I don't know how to change the secound :( ) Any hint?

  • JelF Avatar

    There is some problem with this kata.

    Car prices are implied to be integer values (at least by input). It means, that they should be rounded each month, however example and test cases have written as they are not. It might be quiet misleading

  • roccoVB Avatar

    This comment has been hidden.

  • IvanVukosav Avatar

    In file included from main.cpp:7: ./tests.cpp:9:34: error: call to non-static member function without an object argument vector ans1 = BuyCar::nbMonths(2000, 8000, 1000, 1.5); ~~~~~~~~^~~~~~~~ ./tests.cpp:16:34: error: call to non-static member function without an object argument vector ans1 = BuyCar::nbMonths(12000, 8000, 1000, 1.5); ~~~~~~~~^~~~~~~~ 2 errors generated.

    How do I fix this error?

  • kumar.sanu Avatar

    This comment has been hidden.

  • BunChan Avatar

    This comment has been hidden.

  • sharmalokesh  Avatar

    This comment has been hidden.

  • spgetter Avatar

    I did not like that the solution requires rounding the savings (although stated in the instructions). The true amount of savings should be math.trunc or math.floor, because the bank won't be pitching in the extra cash to bump you to the nearest integer.

  • DajaSvecu Avatar

    Is this kata working? My solution works for 22/25 cases and when I tried using solutions of others it didn't work either.

  • W O W Avatar

    Im not sure, but do we need to increase the savings of $1000 every month?

  • Joshuarvlcb Avatar

    This comment has been hidden.

  • Opabinia Avatar

    Solved it in Reason (thanks to whoever translated it!), but I still find it really hard to write elegant solutions with elegant code in this language compared to Haskell / Clojure 😕

  • lautapa Avatar

    In two of the tests when I click on attempt, there is an error for a single number, example 122 instead of 121, I do not follow it because all the others are good results, I just come to leave it solved because it can happen to another. scala language

  • flink Avatar

    This comment has been hidden.

  • Injustive Avatar

    This comment has been hidden.

  • ckopo Avatar

    Please update Nim version of this kata. I've written a fully passing solution (zero failed tests), but it's being rejected with Error: execution of an external program failed: '/workspace/tests '.

  • Hirador Avatar

    Description is clear enough. Try to build your algorithm more logically, mates.

  • moonorange Avatar

    I'd say the description isn't clear like many other ppl said

  • gitonga123 Avatar

    The assumption is, he selling his old car which depriciates at given a rate , plus the monthly savings, to buy the second hand car which is depriciating at the same rate.

  • Chase X Codex Avatar

    I don't know why but I completely missed the other car's price is also decreasing which missed me up a lot Please highlight that part in the description

  • Mertens Wouter Avatar

    How does the rounding work in c# , I tried it with Math.Round but I get an error and don't understand why Math.Round does not work. Is the rounding off or am I doing the wrong rounding ?

  • michan9 Avatar

    my head hurst @_@

    ... but anw a lot of fun with this.

  • RashDK Avatar

    This comment has been hidden.

  • yegorskikh Avatar

    The task is not clear for whom English is the native language. What can we say about the Russian. And so interesting

  • soleil333 Avatar

    This comment has been hidden.

  • kentDmayor Avatar

    Can someone help me with this one?

    I'm solving this Kata using Pascal FPC 3.2. Whenever I try to return an Integer that was converted to String (e.g. thisValue.ToString or IntToStr(thisValue)), there was an error exception on that specific conversion. Could this be a bug or something?

  • dzielnykompanion Avatar

    In my opinion, description is quite ambigous, but more irritating is the need of rounding available money. Rounding units like money up has no sense for me.

  • jimmy.clayton Avatar

    In summary,

    1. The example has the rate increasing from 1.5% to 2% at then end of the 1st month, not the second as described.
    2. The dollar amount left over needed to be rounded to the nearest dollar. This was never mentioned
  • vladflip Avatar

    The description is confusing. There are two almost equal statements: decrease of 1.5 percent and increases of 0.5 percent. However, from the examples, they mean different things. First one is taking a percent of the values, second one is just an addition to the percent.

    I labeled it as an issue, but looking at this discussion, I guess nobody is going to fix that.

  • juliabakeryuhui0916 Avatar

    I have tried 3 methods to tweak out the meaning of 1.5 % and 0.5 every 2 months. A simple excise is greatly hampered by the confusion in description. I am a financial person. The issue with this kata is that the author needs to read how we finance and economist people do time alligned financial (value of money) apprails. The key assumption is always to tell upfront with the concept of midperiod, startperiod or endperiod. These assumptions yield different result as every second and minute the value of money changes. I stop guessing what is the intention of the author. After trying 3 methods - compounding, simple, and start vs end, I couldn't get 766, always slightly off

  • DimOld Avatar

    Test Results: Test Passed Log [0, 4000] None should equal [0, 4000]

    Error for correct answer How to understand this?

  • The_Paradox Avatar

    another amazing kata g964!!! Not gonna lie though, i struggle with all of them

  • Ozzzzimandias Avatar

    Godzilla had a stroke trying to read this description and died

  • filipjm1 Avatar

    This comment has been hidden.

  • thatch Avatar

    Poor explanation. "this percent of loss increases of 0.5 percent at the end of every two months" isn't true based on the test cases. In order to match the cases you need to increment months at the beginning and update monthly loss as needed at the start of the loop which makes absolutely no sense.

  • FunkScripter Avatar

    This comment has been hidden.

  • krebs01 Avatar

    It says that the loss increses every 2 months, but in the example the loss increased at the end of the firt month.

  • robertDinca2003 Avatar

    Random Test, Test 1 , Test 2 passed the test but Test 3 and 4 failed, why? can someone give an example of input

  • Lubchynsky Avatar

    Rounding? Really? If there are left for example 12.75$ after car buying, it do not mean that we have 13$. Description should be updated!

  • Derek_J_Olson Avatar

    The description of this kata is poor and it seriously needs to be improved. It is not by any means impossible, but it is not at all clear either. It should provide an example and the generic instructions separately, not mixed together into one set. This leads to confusion of which numbers are variables and which are fixed. It is also wrong about the depreciation rates. The description says that the percentloss by month increases at the "end" of the 2nd month. However, to get the correct answers, you must increase this value before calculating the depreciated values of the cars for the second month. This actually means the depreciation rate started at the beginning of the second month. The depreciation takes place over a whole month. If the rate changes at the end of the month, it does not begin depreciating at this rate until the next month.

  • thomasedi Avatar

    0.5% increase on 1.5% results in 1.5075% with increse of 0.0075 percent point. You meant 1.5% with 0.5 percent point increase each month. Fe 10% increase on 40% results in 44% or 40% plus 4 percent point.

  • MERTULAS Avatar

    I give tactics, start at 1.5% from the 1st month and do not take the monthly savings as fixed as 1000, do it according to external values

  • lype Avatar

    The description is tricky :-D

  • Wanni Avatar

    This comment has been hidden.

  • eternalliving Avatar

    I feel like the description was slightly confusing... the interest increase didn't work out how I thought it my head, was just trailing a change when it all worked...

  • mjsspencer Avatar

    My solution works perfect on Codewars, but strange things happen when I use my solution on Visual Studio Code. For example, when the input is (6873.7790013165, 10310.668501974751, 500, 3.0), I get the output (6, 268) on Visual Studio Code but (8, 597) - the correct output - on Codewars, remember, with the exact same solution. I also tested 2 other solutions on VS Code and got the same incorrect output. Please could someone give me an idea as to why?

  • WayneKorir Avatar

    The author should re-evaluate the solution. The solution implies that the increment of depreciation affects the previous month, which seems to contradict the instructions issued. As many have stated, the guidelines should be made clear.

  • michelecaccamo Avatar

    Hi all, can someone help me out with this ? I passed all the test but when attempting I always get an aswer differing on one unit with the expected one, for example:

    expect <749> but was <748> ... any clue of what I'm doing wrong?

  • marblekong Avatar

    Hi, I figured out that the function name and the function parameters should be in snake_case in Python. How can I improve the style guide for this kata for Python?

  • a-dezh Avatar

    I always get [6, 685] in first test. I included 0.5% every 2 months, but I can do nothing more. It's sadly :-(

  • a_pixelation Avatar

    Using Java, I can pass all but two tests. Remaining money is off by +/- 1. :( I've tried using BigDecimal and Round. Wish we didn't have to output an int[], because we're dealing with money.

  • rurbinasal Avatar

    This comment has been hidden.

  • cellar81 Avatar

    This must be a Japanese example - in classical economics, prices for new stuff tends to go up ;-).

  • funnybiscuit Avatar

    This comment has been hidden.

  • Pudge601 Avatar

    In C++, it would be more appropriate to use a return type of pair rather than vector; this is probably the same for any other supported languages which have the concept of a pair or tuple.

  • AymanAtallahAhmed Avatar

    language: swift

    in Buying a Care Kata the code does not compile and show this message " main.swift:13:70: error: cannot convert value of type 'Int' to expected argument type 'Double' let act: (Int, Int) = nbMonths(startPriceOld, startPriceNew, savingPerMonth, percentLossByMonth) ^~~~~~~~~~~~~~ Double( ) " although it runs well in xcode playground with all cases without problems

  • idopshik Avatar

    excelent kata. Perfect explanation.

  • nsutcliffe Avatar

    This comment has been hidden.

  • a.stulov Avatar

    I had a random test case buyACar(2700, 2700, 1000, 1.4)).toStrictEqual([0, 0]). My code gave here [1,1000]. Next attempt successfully submitted with the same code.

  • Blackdevil007 Avatar

    This comment has been hidden.

  • mattaschmann Avatar

    This comment has been hidden.

  • ArunNagul Avatar

    This comment has been hidden.

  • gvilardo Avatar

    Be more precise on stuff like rounding and whatever else or just avoid, it's trial and error on decimal stuff that has not much to do with algorithms and more like time spent moving knobs on decimal places.

  • Lomig Avatar

    The description prevents a good understanding of what we have to do; that was not pleasing at all.

  • Terrence Xu Avatar

    Hint for Go: please don't use math.Floor but math.Round~

  • willm78 Avatar

    The instructions for this kata are horribly unclear.

  • reineCook Avatar

    Definitely needs some clarification for constraints. e.g. does the loss every two months increase in absolute value (percentLossByMonth+0.005) or does it increase in relative value (percentLossByMonth *1.005)?

  • dapo_t Avatar

    Most of the java tests are incorrect. I solved the same Kata in Js with the same code and it worked perfectly. Paased all the test.Theres definately something wrong the funtionality of the java tests because this has happend severally.

  • RoastedPieces Avatar

    The return values should be notated as tuples (and not as lists): For example: nbMonths(12000, 8000, 1000, 1.5) should return [0, 4000] should be nbMonths(12000, 8000, 1000, 1.5) should return {0, 4000}

    And what is the or (6,766) supposed to be in: nbMonths(2000, 8000, 1000, 1.5) should return [6, 766] or (6, 766)?

    Edit: I just realized that the descriptions are shared across languages. I did it in elixir and it was a bit confusing.

  • Hebanek Avatar

    Yo, I have a question. While testing, line int act = nbMonths(startPriceOld, startPriceNew, savingperMonth, percentLossByMonth);, has a correct value e.g. printf("%d, %d", act[0], act[1]) gives 0, 4000. but he line, char sact = array2StringInt(act, 2);, doesn't work, printf("%s", sact) gives out 0, 0. Why is that? I don't understand.

  • thekidxp Avatar

    Having trouble completing this kata. On top of the order of operations issues that other people have mentioned. The array2StringInt function seems to be mangling my answer and I'm not sure why. If I place this printf("Error. Expected %d but got %d\n", *(expr+1), *(act+1)); or printf("Error. Expected %d but got %d\n", *expr, *act); before that function my numbers match up with the given array. After that function my array values and string values become nonsense. I'm attempting to do the kata in C.

  • ChrisWatkins Avatar

    The instructions on this Kata need to be made far more clear.

    For one - you must increase the percent of devaluing at the beginning of month 2, or you will not get the correct answer.

    The instructions counter intuitively state Furthermore this percent of loss increases by 0.5 percent at the end of every two months. meaning I only came to this conclusion via trial and error.

    On top of this, the level of rounding required is entirely unclear.

    When recalculating the new value each month, do we need to round the figure? Up/Down? To how many places?

    So far, no matter what combination of rounding methods I use, I always have at least 3 test cases where my remaining figure is out by 1 - I'm slowly moving my decimal out, and will hopefully hit it soon.

    This is an interesting Kata, and as a Junior who is learning I have found it useful in many ways - the best lesson is that requirements should be clear from the get go.

  • 4dagoth Avatar
            |start of month 1 - Current value and no loss yet
            |end of month 1|1.5%
            |end of month 2|1.5%
            |start of month 3 - this is by definition every 2 months
    

    it is clearly stated in the exercise that calculations happen at the end of the month but the increase of percentLossByMonth is increased "every 2 months" which will mean that the first increase happens at the start of month 3.

    Otherwise the first increase happens BEFORE 2 months have passed, and then every 2 months after that, which would be insane.

  • Naraku777 Avatar

    I have a problem with passing test 4 and test 5 using Java. "arrays first differed at element [1]; expected:<332> but was:<331>" in test 4 and "arrays first differed at element [1]; expected:<122> but was:<121>" in test 5. So I get the result which is only one less then the one I need. But it's OK in other tests, including sample ones. I think there might be a problem with rounding, but I can't figure out what kind of problem exactly.

  • Sepero Avatar

    "A man has a rather old car being worth $2000." I assume this means, "$2,000 trade-in value.", and therefore should be deducted from the new purchase cost...

  • SUSREE64 Avatar

    This comment has been hidden.

  • peda Avatar

    It is impossible to know if the bi-monthly loss increase should first be applied at the end of the first or second month. It is thus impossible to get the kata right without luck or trial and error.

    Please fix the description.

  • aweza Avatar

    This comment has been hidden.

  • vivi00790 Avatar
    1. Yes, I know decrease can be follow by both by and of, BUT IN DIFFERENT CASES, please reffer to Cambridge Dictionary. but "a decrease of 20,000" -> NOUN -2000 Yearly sales decreased by five percent. -> VERB *0.95 "..the prices of his old car and of the new one decrease of 1.5 percent per month..." decrease in this kata should be verb iirc, so you need to use by to prevent confusing Same, "...this percent of loss increases by 0.5 percent..." should be "a increase of 0.5 persent" instead.
    2. And "All operations are considered at the end of the months" you said? No, there're not. The depreciation each month of your sample test 6,766 is {0.985, 0.98, 0.98, 0.975, 0.975, 0.97}. Depreciation is increased at THE START OF EVERY TWO MONTH. Unless you don't count depreciation increasing as an "operation", in this case you should explain it in the Kata to, again, prevent confusing. This issue is mentinoned in the discourse several times, I don't know why you seem not want to fix it. Just...just look at the satisfacation rating, do you REALLY think the ONLY problem is that we couldn't even read "simple English", sensei?
  • vivi00790 Avatar

    Kata: ...Furthermore the percent of loss increases by a fixed 0.5 percent at the end of every two months. ... And all the test increse it at the XXXXing START of every two months.

    LOTS OF grammar fail even I'm not native English user can point it out. ex: decrease of(X) decrease by(O)

    Also, parameter savingperMonth(X), should be savingPerMonth

  • Krazed35 Avatar

    This is throwing up random grammar errors for words that are correctly spelled, not sure if it's this kata or something wrong with the site

  • padwas Avatar

    This could have been a great kata if the discription was not so awful, honestly the 69% satisfaction rate is kind considering just how many assumptions are required to complete this.

  • zackzeyu Avatar

    The description is horrendous and includes an incorrect statement, specifically "...this percent of loss increases by 0.5 percent at the end of every two months"

    To pass, you actually have to assume that the percentage loss increase happens at the beginning of every two months (or the end of the previous month). For example in the first test case, if your code passes, it should report the value of the old car to be 1930.6 at the end of month 2, meaning that the car depreciated by 2.0% during month 2. That should not be the case, since according to the description the percentage loss should not increase from 1.5% to 2.0% until the END of month 2 (i.e., the car should've only depreciated by 1.5% in month 2).

  • gaborpelesz Avatar

    This comment has been hidden.

  • hongsw Avatar

    I like Kata. Now I can not only learn Elixir but also understad Elixir + Pattern Matching of Function. Even if my code was still procedural programing style, it was great time to learn elixir and code reviewing clever codes.

  • richard.gaugler Avatar

    I just gave up.
    I don't get what was wrong with my code and I won't post it here, I tried many things but it seems I don't get everything.
    This is really frustrating, I've got the feeling that the instructions are unclear but since I haven't completed it I don't want to exclude the possibility that I'm just an idiot :(

  • dagolinuxoid Avatar

    This comment has been hidden.

  • psim1 Avatar

    I think the question was worded very poorly. I interpreted it as the loss increasing by 0.5%, meaning a loss of 1% would now go to 1.005%. However, you are really just adding .5% to the loss, so a loss of 1% would go to 1.5% .... Spent way too long trying to figure out the issue with my code, but this solved it.

  • S_Sri Avatar

    I have problems while rounding values in java.The answer to some sample tests(not all) is one less or one more than expected answer. Is anyone facing the same ? Its defintely a time waste kata

  • RA3TH Avatar

    This comment has been hidden.

  • vasiliy-pdk Avatar

    Do we have a math Guru who has managed to solve this through an equation? :)

  • zeronumbers Avatar

    in clojure how do you solve this? 2 tests fail becuase of rounding. the only rounding procedure that i found is int but it gives incorrect answer in this 2 tests because (int 2.9) is 2

    also i accidentally deleted ns, how it looks like?

  • JasonYang960305 Avatar

    The description is really makes people misunderstanding, the right thing should be: the first month of the decrease percentage is 1.5%, 2 and 3 month is 2.0%, 4 and 5 mouth is 2.5%... only in this way we could got the right output... waste my 2 hours...::>_<::

  • acmoune Avatar

    Good kata

  • OleksandrChekalenko Avatar

    Do not use Math.round... use Math.floor !!!!! at this Kata)

  • rrogerthat Avatar

    The problem starts with trying to understand the question itself with the horrendous grammar. Do these probems get reviewed before being created? Interesting how this is also an accounting based question.

  • FArekkusu Avatar

    The description should be rewritten slightly:

    1. "766 is the nearest integer to '766.158..." - this part is hard to notice. Simply say that the final value should be rounded.
    2. It should be clarified that the example at the beginning is indeed an example, and not part of the task explanation. "Furthermore the percent of loss increases by a fixed 0.5 percent at the end of every two months." - this part is especially baffling because "fixed 0.5" sounds like this value is a constant.
  • antoni-g Avatar

    This question, as many have stated, has very unclear documentation. This isn't a difficult question by any means, a basic compounded percentage problem. This question however is extremely unclear on multiple points in its description. The ones I caught:

    • The order of each event occuring (depriciation, purchasing and saving) is unclear. The correct order to get the result the test cases one needs to FIRST adjust the percentage if necessary. The ordering for these operations is ultimately arbitrary, but the depriciation percent happening before or after calculations is important to get the exact result.

    • The months where depriciation occurs isn't clear. Month 0 is used as a corner case test, but it isn't clear if month 0 is the first month with depriciation or not. To get this correct, it is before any calculations have taken place (ie, old car is worth 12000 and new is 8000 on the spot, meaning you can purchase it right away with 4000 in savings). Month 1 is therefore the first month that calculations and savings have taken place. This is again, arbitrary to decide but must be clearly stated.

    • The exact method for increasing depriciation is unclear. Does it increase after calculations or before? Again, the trend here is this decision is arbtrary but not clear. This must be explictly stated - right now, the adjustment to the percentage happens before any calculations take place.

    • The months that have depriciation are not clear stated. Make it clear that month 0 is before any calculations, month 1 is with calculations and no adjustments, and then month 2 calculates the depriciation at the beginning of the month, the pattern continues etc.

    • The rounding is arbitrary - it could just as easily be a floor as a round and neither perfectly makes sense (it is necessary, given that the result is a floating point number). Make it clear the answer needs to be rounded to the nearest integer (it is stated but not exactly clear).

    • Please, please remove the constants from the description as though they are set in stone. Accurately refer to the fact that the monthly savings are a variable instead of simply saying "1000" but inconsistently refering to other variables correctly as variables.

    Ultimately, this is a very simple Kata, a little bit of a brain teaser to make programmers aware of floating point accuracy and such. But with something as sensitive to results like this, the instructions have to be watertight. Otherwise you will dissuade/discourage many programmers who are getting very close answers that are slightly off, where the only solution is to continously reorder operations until you can guess what the submitter was thinking at the time.

  • 7097511 Avatar

    Kata shows what real problems will have to be solved by those who choose the profession of a programmer.

  • skyboundgrey Avatar

    I agree with most people here that this was poorly worded. I spent a good hour trying to get the remaining balance right. I knew there was something wrong with the percentage increments "every two months". It increases in the 2nd month AFTER the calculation to decrease the prices of the cars.

  • GabrielSaul Avatar

    One of the most poorly-described katas I have encountered. 2 hours wasted, but a great lesson in anger management. May its creator burn in hell.

  • bchellingworth Avatar

    Very poorly worded question! There are so many different ways you could interprept the bi-monthly 0.5 pct. For example, is it 0.5 of the monthly valuation pre or post the 1.5 deduction? is it 0.5 of the value last time you deducted 0.5 (i.e. two months ago) or is it that the monthly 1.5 increases by 0.5 every 2 months (i.e. month 1 = 1.5%, month 2 = 2%, month 3 = 2%, month 4 = 2.5% etc).

    FYI its the last one.

  • Lu_the_Zy Avatar

    I would just like to clarify, the percentage decrease applies to both new and old car price, right? Secondly, if prices are going to be decreased by decimal values why would they be passed in as integers and not double or decimal?

  • Phil157 Avatar

    I had a random test (data = 5864, 8410, 1193, 1.5) fail with a value just below x.5000 (in both my Fortran & Excel) being rounded UP to x + 1, so I added a halfpenny!

  • cfsanderson Avatar

    The description was unnecessarily unclear and lead me in the wrong direction. Thanks to @creightonja 's (and others) comments I learned the intended incrementing pattern of the bi-monthly percentage - 1.5 in month 1, 2 in month 2, 2 in month 3, and 2.5 in month 4, etc.

  • creightonja Avatar

    This had a lot of potential, but the poor explanation of the variables and how they change made it needlessly confusing.

    I had to read the comments to see how the depreciation value changed month by month. I originally had it set up to change at the end of the 2nd month, thereby increasing the depreciation rate in the 3rd month's calculation. Luckily I found a comment that showed it was 1.5 in month 1, 2 in month 2, 2 in month 3, and 2.5 in month 4.

  • cdaringe Avatar

    This comment has been hidden.

  • Carpathian Avatar

    I have solved it,but this task is a waste of time...

  • caheredia Avatar

    Overall very poorly written question. I had to re-read everything over and over for complete comprehension. And for the final result to work with all test cases I needed to use round() instead of int(). This is a poor use of time. If something that insignificant is going to pass everything save for one test case, then the round outcome should be explicitly requested.

  • zfk513 Avatar

    the every two months is absoluately confusing. the reason why i spend two hours.lol

  • sehe Avatar

    The wording "Furthermore the percent of loss [...]" clearly implies that it only goes for the depreciation of the OLD car, not the new (that's a WIN, not a LOSS)

    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.

    is WAY more accurate. (thanks to designerzim)

  • jacketgun Avatar

    This comment has been hidden.

  • dexed Avatar

    This comment has been hidden.

  • Marcelovv2 Avatar

    I have 42 right and 3 wrong, I dont get what is happening here, what are the numbers for those test's? Thanks

    Basic tests Test Passed: Value == '[6, 766]' Test Passed: Value == '[0, 4000]' Expected: '[8, 597]', instead got: '[4, 235]' Expected: '[8, 332]', instead got: '[11, 542]' Expected: '[25, 122]', instead got: '[15, 469]'

  • flobka Avatar

    I think the elixir description is wrong. I state it can be either returned a list [month, moneyLeft] or (month, moneyLeft), however to pass the "Attempt" you need to return a tuple {month, moneyLeft}. I somehow can't suggest a change in the description.

  • untanglereality Avatar

    If you are using Python, use round() instead of int() to approximate the result, otherwise, in my case, one of the tests wouldn't pass.

  • Blizzard2795 Avatar

    You probably shouldn't give a static savings amount in the description if a couple tests don't use it. It took me way too long to realize my problem was using said number instead of the variable, granted that there was a variable in the first place meant I probably should've used it.

  • Blind4Basics Avatar

    Hi,

    there is a small mistake in the description:

    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 ... should be:

    If, for example, at the end of first month the percent of loss is 1.5, at the 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 ...

    I wanted to update the description, but I got a message saying that modifications have been made and not published, so I preferred to avoid any troubles and didn't do it.

    cheers,

    B4B

  • NMAC Avatar

    26 corrects and the others error why? :(

  • ori0n Avatar

    This comment has been hidden.

  • user9433125 Avatar

    Instructions are too complicated. Gave up after 30 minutes unable to figure out what to round.

  • kiki.su Avatar

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

    The statement should correct as

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

    The describtion of this question is too diffcult to understand.

  • cypherrage Avatar

    This comment has been hidden.

  • Dokkum Avatar

    This comment has been hidden.

  • mecv Avatar

    It helped to skim over the discourse prior to attempting this Kata. In particular, the improved description provided by designerzim was comprehensive and cleared potential misunderstandings.

  • carlos.pantelides Avatar

    C:

    I have a working algorithm but I'm having trouble with returning the array. Commenting out the call to free() works fine with the example test. If not, I get an

    *** Error in `/home/codewarrior/solution': munmap_chunk(): invalid pointer: 0x00007ffd94be9eb0 ***

    int* nbMonths(int startPriceOld, int startPriceNew, int savingperMonth, double percentLossByMonth) { int * result; result = (int *) malloc(result); ... return result; }

    void dotest(int startPriceOld, int startPriceNew, int savingperMonth, double percentLossByMonth, int *expr) { .... //free(act); act = NULL;

    Any advice?

  • kbgoda Avatar

    This comment has been hidden.

  • carlos.pantelides Avatar

    This comment has been hidden.

  • krasM Avatar

    Nice kata, I've somewhat figured out the solution, but the problems were with the floating point in java, which gave me a good headache :D

  • rsdah13 Avatar

    This comment has been hidden.

  • Austin Haws Avatar

    This comment has been hidden.

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

  • jamm Avatar

    I passed 1 test and after I always get error:

    *** Error in `/home/codewarrior/solution': munmap_chunk(): invalid pointer: 0x00000000006021b4 ***
    
  • Schaef_Jo Avatar

    What is the second return? How much he has left from the money from his old car after buying the new one or is it the price of the new one? The latter doesn't make that much sense because in one example it was 12k (old car) and 8k (new one) and the number was 4k so obviously subtraction however the 700 and something confuse me. It would be amazing to see one calculative example instead of what kind of input you get (which is also nice but not that important). Additionally the first part of the instruction just confuses since there are real numbers but they aren't even the ones you calculate with.

  • stenkoff Avatar

    poor, over-complicated explanation/directions that made the problem difficult to understand

  • int3rsys Avatar

    This comment has been hidden.

  • DSchwettmann Avatar

    The documentation is very lackluster. It doesn't specify in which order the calculations are done, when rounding occurs, etc. Implementing the base is trivial, but then figuring out which order the tests want you to perform the calculations in is tedious.

  • CoffeeToCode Avatar

    It not that hard. It maybe 7-8 kyu, not 6 kyu.

  • memiscet Avatar

    the real Kata should be to understand the question. :)

  • pbywater Avatar

    All my tests are coming back correct with no fails but for some reason I'm unable to submit! :(. Can anyone help?

  • rathi Avatar

    Hi . i am wondering when all my test are resulting correct , what is going wrong on my last test for this kata Test Results: ✔ Test Passed: Value == [6, 766] ✔ Test Passed: Value == [0, 4000] ✘ Expected: [8, 597], instead got: [8, 563]

  • yuens1002 Avatar

    This comment has been hidden.

  • Magistairs Avatar

    All tests seems to give 2000,8000 as arguments?

  • Pasi Hattu Avatar

    The documentation got me all mixed up. You have to notice that even though the instructions say "the man saves ~1000$ month" the real input might be different (from parameter). This is pretty simple and basic stuff but for somehow I took that 1K as granted and did lots of waste work.

  • FFF1243 Avatar

    Really bad documented... all i can say

  • bja Avatar

    This was both boring, and horribly documented. You need to figure out that you only round on the final value, but that means that int's that they passed don't actually work. Furthermore the test cases don't actually help since there are rounding complaints that make it both boring to debug and a pain to solve.

  • CodingXero69 Avatar

    Very boring, waste my time.

  • lvsz Avatar

    For people using Haskell, changing the type signature to nbMonths :: (Enum a, RealFrac a) => a -> a -> a -> a -> [Integer] will save you a lot of type coercions.

  • foolnotion Avatar

    The code is idiotically simple, time wasted with this kata trying to understand the unnecessarily complicated problem formulation.

  • mmalkavian Avatar

    I really don't get what this percent of loss is related about:

    • to the initial old car price,
    • to the initial new car price,
    • to both,
    • to the old car price getting updated every month,
    • to the new car price getting updated every month,
    • to both the above,
    • to the initial price difference between old and new car,
    • to the updated price difference between old and new car,
    • is the saving included in the percent of loss

    ?

    I'm puzzled. This kata is not difficult to solve, rather to understand.

  • TudorTacal Avatar

    This comment has been hidden.

  • Toderesa97 Avatar

    This comment has been hidden.

  • jonas-wagner Avatar

    In C++ the public testcases don't use 'namespace std' and therefore throw errors.

  • _Onion Avatar

    C# Can't understand what the problem with Math.Round(). Test 3 and Random tests are failed. If I have no use Math.Round() Test 1, 4 and Random are failed. I've read all of comments:)

    startPriceOld -= (int)Math.Round(startPriceOld * percentLossByMonth / 100.0); startPriceNew -= (int)Math.Round(startPriceNew * percentLossByMonth / 100.0);

    Can somebody tell me where is my mistake?

  • user5036852 Avatar

    Nice, challenging kata! Thanx!