There have been some tax rate calculator problems here that depend on defined rates (specifically US federal rates), but none that have done it for arbitrary lists.
Your task is to build a program or function that will take an arbitrary list of marginal tax brackets and calculate the effective amount of tax paid on a given amount of taxable income.
Your program will take as input:
Npairs of numbers in the form
(amt, rate), each representing a tax bracket.
amtis the amount of taxable income above which at which the tax rate starts to apply. These amounts will all be integers, and appear in increasing order.
rateis the tax rate, expressed as a decimal percentage from 0 to 100 inclusive.
The amount of taxable income, as a nonnegative integer.
If no rate is specified for $0, the rate is assumed to be 0%.
Alternatively, your program can also take as input two lists
(amt1, amt2, ...) and
(rate1, rate2, ...), containing the amounts and rates in the same order.
Your program will then output the payable tax, either to two decimal places, or rounded down to the nearest whole currency unit.
An example input (the most recent Canadian tax brackets, from 2016, with the basic personal tax credit applied and nothing else):
11474 15 45282 20.5 90563 26 140388 29 200000 33 393216
And its corresponding output:
108357.07 or 108357
The shortest program in any language to do this wins.