6 kyu

Financing a purchase

281 of 935g964
Description
Loading description...
Fundamentals
Mathematics
  • Please sign in or sign up to leave a comment.
  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • xianjin Avatar

    I think to be fully correct there also has to be a test case with rate 0.0.

  • padafka Avatar

    This comment has been hidden.

  • dfhwze Avatar

    Nim: solution setup does not compile -> missing *

  • Krillan Avatar

    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.

  • B1ts Avatar

    Nim:

    • returning anything seems to pass all the random tests, but crashes on fixed tests
    • The way it crashes fixed tests needs to be looked at (no failed test, just some warning)
    • Sample tests shouldn't include randomization

    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.

  • BitemNet Avatar

    I guess there is a problem because with the formatting you suggest (and most people have solved it that way):

    the function amort will return a formatted string (for example):
    "num_payment% d c% .0f princ% .0f int% .0f balance% .0f" (with arguments num_payment, c, princ, int, balance)
    

    the following test:

    test.assert_equals(amort(6, 100_000, 360, 360), "num_payment 360 c 600 princ 597 int 3 balance 0")
    

    does not pass because it gives the following result:

    'num_payment 360 c 600 princ 597 int 3 balance -0' should equal 'num_payment 360 c 600 princ 597 int 3 balance 0'
    

    Nothing like that, because 0 = -0 but the strings are different ;)

  • startfrom0 Avatar

    How exactly should I return the values? Bc when I return it as a list I get the following code.

    Test Failed
        argument 2 (type 'list') cannot be handled by 'cat'
        1: testing(7.4, 10215, 24, 20, "num_payment 20 c 459 princ 445 int 14 balance 1809") at tests.R:10
        2: cat("actual", actual, "\n") at tests.R:4
    
  • gilesejb Avatar

    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.

  • username0 Avatar

    Rust sample tests seem to be the same test twice. Suggeting that the duplcate test be changed or removed.

  • dbrown2umassd Avatar

    This comment has been hidden.

  • monadius Avatar

    CommonLisp: The following line should be added to the solution and test code:

    (setq *read-default-float-format* 'double-float)
    

    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.

  • monadius Avatar

    This comment has been hidden.

  • kirilldbr Avatar

    Shouldn't we use BigDecimal for finance instead of double?

  • Infinite Pest Avatar

    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

  • Glyxerine Avatar

    Some terminal in Ruby Description are not uniform such "r", "rate".

  • eb110 Avatar

    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.

  • xavierguihot Avatar

    May I suggest in the Scala translation to rename parameter num_payments as numPayments?

  • MusicalCoder Avatar

    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

  • kortizzion Avatar

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

  • Voile Avatar

    Description has inconsistent examples:

    amort(6, 100000, 360, 1) ->
    "num_payment 1, c 600, princ 100, int 500, balance 99900"
    
    "num_payment %d c %.0f princ %.0f int %.0f balance %.0f" (with arguments num_payment, c, princ, int, balance)
    
    Test.assertEquals(amort(7.4, 10215, 24, 20), "num_payment 20 c 459 princ 445 int 14 balance 1809")
    

    There are no commas between the variables.

  • Voile Avatar
    amort(6, 100000, 360, 360) ->
    "num_payment 360, c 600, princ 597, int 3, balance -0"
    

    -0?

  • marbiru Avatar

    possible typo: in the function you use numpayments and in the return string numpayment (no s)

  • anter69 Avatar

    Haven't solved it yet, but isn't it the same as this one? https://www.codewars.com/kata/calculate-monthly-mortgage-payment

  • ZED.CWT Avatar
  • ZED.CWT Avatar

    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.