6 kyu
Financing a purchase
281 of 935g964
Loading description...
Fundamentals
Mathematics
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.
python new test framework is required. updated in this fork
I think to be fully correct there also has to be a test case with rate 0.0.
This comment has been hidden.
Asking for help is not a kata issue.
This comment has been hidden.
Nim: solution setup does not compile -> missing *
Added "*".
You need to add the formula for obtaining int (int == bal(n-1) * rate / 100/12) to the description, perhaps this seems obvious to the author, but it wasn’t for me, I wasted half an hour reading an article from Wikipedia and only then removed it from the table by typing, nor neither was interesting or useful.
Nim:
I'm new to Nim so I'm not sure how standart these things are, but I didn't experience anything similar on easier katas, so I believe it's an issue.
Late! but I saw your post just now. The test function was ill-placed plus unuseful things. I forked the translation and your solution passes without any problem.
I guess there is a problem because with the formatting you suggest (and most people have solved it that way):
the following test:
does not pass because it gives the following result:
Nothing like that, because
0 = -0
but the strings are different ;)Sorry but I don't see there a kata issue.
How exactly should I return the values? Bc when I return it as a list I get the following code.
It's a question, not a kata issue.
I couldn't complete this without help from Wikipedia, and even then I couldn't figure out what precision to use where to get exactly the same numbers. All my answers were correct except for the final balance being off by a few dollars. Some guidance on precision would've made this a reasonable Kata. As it is, thumbs way down.
Rust sample tests seem to be the same test twice. Suggeting that the duplcate test be changed or removed.
Done, thanks.
This comment has been hidden.
Read the error message, your output has a leading and a trailing space.
And please, when posting code like that, mark your post as having spoiler content next time.
Thank you.. that waas it.. Will do moving forward..
CommonLisp: The following line should be added to the solution and test code:
As I understand, CommonLisp uses single precision floating-point numbers by default. Single precision floating-point arithmetic may yield inaccurate results. For example, my solution does not pass some random tests because of this issue.
Before publishing I tried my solution with your proposition but I didn't see any difference in the results so I didn't take this modification for the definitive reference solution. To be on the safe side the results are accepted in Common Lisp with a tolerance of one (you can see function "dotest") and I thought it was sufficient.
I will introduce "double-float".
This comment has been hidden.
Modified. I didn't add this line in my first tries to the good place... Once again lots of thanks for your patience!
Everything works now.
I also tried double precision floats in your Floating-point Approximation(II) kata. It was not enough to change the default precision format. For some reason, it was also necessary to change the provided
trunc
function:I don't think you need to update that kata because floating-point errors do not accumulate too much there.
This comment has been hidden.
OK. Length tested!
Shouldn't we use BigDecimal for finance instead of double?
Could give a better precision in some cases but since the results are in a string with "%.0f" I think it is not in the spirit of the kata. I am sorry to see that you used them:-(
I do not think that the description makes sense financially:
"rate - the monthly interest rate is expressed as a decimal, not a percentage. The monthly rate is simply the given yearly percentage rate divided by 100 and then by 12."
The dependency between monthly and annual rates is exponential, not multiplicative. Writing the monthly rate m and the annual rate a as decimals, the correct relationship should be:
(1 + m) ** 12 = 1 + a
Some terminal in Ruby Description are not uniform such "r", "rate".
As a programmer i should to create a user requirements. Your Kata has only 76% which mean potential programmers hasn't received all necessary information. I have a several question to you as you are my potential customer. To how many decimal places i should to round as follow : balance, interest, percentage?(monthly basis) To count rate i have to power variable to number of months. To how many decimal places i should to round it in every circle? Which variable i should to round away from zero and which i should to round as even? Programmers are not bankers. They don't have to have knowledge in that matters.
The only banker's requirement is the format of the returned string:
"num_payment %d c %.0f princ %.0f int %.0f balance %.0f" (with arguments num_payment, c, princ, int, balance)
and to show what he wants the 10 sample tests. For the rest you do as you want (don't mind about decimal places or rounding): I am a banker, not a coder:-). Thanks for your posts! Cheers.Saturday morning - i've decided to start from the scratch. 10 minutes and kata is finished. This time i've diecided to not round anything till the final printout and...it worked. So i assume your sentence "The only banker's requirement is the format of the returned string" was the key to understand your requirements. You have received a positive vote from me (rating up to 77%).
Good, I am happy you succeeded so fast! Thanks for all.
May I suggest in the
Scala
translation to rename parameternum_payments
asnumPayments
?I can rename it in the "initial solution: there
Will it be sufficient for you? Note from Scala naming-conventions: "Underscores in names (_) are not actually forbidden by the compiler, but are strongly discouraged ..." Bonne fin de journée!
Perfect, thanks!
test.assert_equals(amort(5.6, 133555, 60, 53), "num_payment 53 c 2557 princ 2464 int 93 balance 17571")
I kept failing this due to rounding - my int was 94
Loans are structured so that the amount of principal returned to the borrower starts out small and increases with each mortgage payment. Tell me please where are you get increase rate And What is it mean (test.assert_equals(amort(1.9, 19121, 48, 2), "num_payment 2 c 414 princ 384 in balance 18353"))?
Description has inconsistent examples:
There are no commas between the variables.
Examples corrected.
-0
?I suppressed this example. Shell bash and JS return "-0" with these data...
;-)
possible typo: in the function you use
numpayments
and in the return stringnumpayment
(no s)Haven't solved it yet, but isn't it the same as this one? https://www.codewars.com/kata/calculate-monthly-mortgage-payment
I didn't see the one you mention. I think this one is more complete.
That kata just requires calculate
The payment c
, while this one expects something more.Resolved since the linked kata has been retired / didn't passed beta.
JavaScript Translation Python Translation
Both approved, thanks!
It is
"num_payment %d, c %.0f, princ %.0f, int %.0f, balance %.0f"
in the description, but it actually is"num_payment %d c %.0f princ %.0f int %.0f balance %.0f"
in the tests.Fixed, thanks!