Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Simple and funny programming problem, good job.
This comment is hidden because it contains spoiler information about the solution
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?
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 neark + 0.5
, where small differences in floating-point arithmetics can make some solutions round up, others down.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.
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.
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?
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.)
and a complete breakdown example like mortonfox did should be part of the description
It appears my solution is off by one. Let's try to work this out by hand:
Yearly tax:
total tax = 74048.6, rounded to 74049
National Insurance:
Monthly Income = 209148 / 12 = 17429
total NI = 846.4825 * 12 = 10157.79, rounded to 10158
Remaining = 209148 - 74049 - 10158 = 124941
How did the reference solution get 124942?
No shit. The description is just awful right now: nothing is explained. I'll resolve the question, since this should be multiple issues instead.
Basically if you owe NI, it's calculated based on your pre-tax yearly income, and not on the tax adjusted income.
Can you explain what that means?
Yep sorry, easy mistake
Ok have reduced them
Loading more items...