Ad
  • Custom User Avatar

    Simple and funny programming problem, good job.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    The description is unclear how NI is related to the overall calculation, and it's not mentioned what is the input. Is it the monthly pay or the yearly pay?

  • Custom User Avatar

    Consider removing the rounding, and just check the result approximately (e.g., to within 1e-6 absolute or relative error, or whatever the Codewars standard is). This will immediately make incorrect solutions not pass, even if they are not (randomly) tested at difficult inputs near bracket changes. Furthermore, it will eliminate any chance of having to round near k + 0.5, where small differences in floating-point arithmetics can make some solutions round up, others down.

  • Custom User Avatar

    Please make it such that at each tax bracket change, 10x'th pound is taxed at the previous rate and 10x+1'th pound at the next rate. Anything else is confusing and not in line with the description. For example, if the current reference solution is given the input 12572, it will only tax the 12572nd pound, not the 12571st pound.

    A similar problem holds for the insurance cost. From the description it's not clear how the 1048th pound is to be taxed.

  • Custom User Avatar

    Both 50270th and 50271st pound are taxed at 20%, 150,000th pound at 40%, and 150,001st pound at 45%. In other words, the bracket changes are quite inconsistent. It would be much more intuitive if the change happened consistently between the 10x-th and 10x+1-th pounds.

  • Custom User Avatar

    How is the pound between 50270 and 50271 handled in the reference solution? Is that particular pound taxed at 20% or 40%?

    Is there a similar gotcha between 150000 and 150001?

  • Custom User Avatar

    12571 to 50270: tax = 20% * 37700 = 7540

    In the reference solution, the respective taxable amount is 50270 - 12571 = 37699. In other words, the first pound after 12570 is not taxed, which is very unintuitive, and should be marked as an issue. (This kind of one-off issues are the bane of taxation katas, and probably one reason why there are so few approved.)

  • Default User Avatar

    and a complete breakdown example like mortonfox did should be part of the description

  • Custom User Avatar
    £209148
    expected 124941 to deeply equal 124942
    

    It appears my solution is off by one. Let's try to work this out by hand:


    Yearly tax:

    • First 12570: tax = 0
    • 12571 to 50270: tax = 20% * 37700 = 7540
    • 50271 to 150000: tax = 40% * 99730 = 39892
    • over 150000: tax = 45% * 59148 = 26616.60

    total tax = 74048.6, rounded to 74049


    National Insurance:

    Monthly Income = 209148 / 12 = 17429

    • First 1048: NI = 0
    • 1048 to 4189: NI = 13.25% * 3141 = 416.1825
    • over 4189: NI = 3.25% * 13240 = 430.30

    total NI = 846.4825 * 12 = 10157.79, rounded to 10158


    Remaining = 209148 - 74049 - 10158 = 124941

    How did the reference solution get 124942?

  • Custom User Avatar

    No shit. The description is just awful right now: nothing is explained. I'll resolve the question, since this should be multiple issues instead.

  • Custom User Avatar

    Basically if you owe NI, it's calculated based on your pre-tax yearly income, and not on the tax adjusted income.

  • Custom User Avatar

    It should be pointed out, National insurance is taken at a pre tax level

    Can you explain what that means?

  • Default User Avatar

    Yep sorry, easy mistake

  • Default User Avatar

    Ok have reduced them

  • Loading more items...