Ad
  • Custom User Avatar
  • Custom User Avatar

    For some reason Codewars submitted an unrefactored version of this solution. The final version of this is very different and removes a lot of the unnecessary elements in this version.

  • Custom User Avatar

    Because we are dealing with integers, C# division or modulus by zero already throws a DivideByZeroException. There's no need to explicitly build and throw one. If we were using floats or doubles, we would get one of the infinities (or in the case of 0.0 / 0.0 or 0.0 % 0.0, NaN) as a result and would need to do further work to handle that.

  • Custom User Avatar

    This is the correct "best practices" solution.

  • Custom User Avatar

    A fantastic kata, one of the best!!

  • Custom User Avatar

    That is my point, except that "N/A or an infinite number of years" in this case means an infinite loop, causing the application to freeze. This would not be best practices, as over 100 votes have claimed.

    If invalid input is given to this method, it doesn't indicate it by either a returned value or an exception; instead, it just never returns at all.

    That is what my question was trying to illuminate: if tax is not less than 1 or if interest is not greater than 0, what happens is a frozen application.

  • Custom User Avatar

    If tax is = 1 or more that means they're being taxed at 100% or more.
    They will never meet the DesiredPrincipal and the answer is now N/A or an infinite number of years, because no matter how many years this man waits his initial value will never increase to meet the desired value

    Similar answer to interest not being greater than 0, the answer is N/A or infinite number of years, as his initial value will never increase to hit the DesiredPrincipal value

  • Custom User Avatar

    For c# this solution actually includes the dividebyZeroException that was asked

  • Custom User Avatar

    323 = 17 * 19

  • Custom User Avatar

    What will happen if Tax is not less than 1 or if interest is not greater than 0?