Skip to content

Instantly share code, notes, and snippets.

@mjwillson
Created October 29, 2009 22:41
Show Gist options
  • Save mjwillson/221907 to your computer and use it in GitHub Desktop.
Save mjwillson/221907 to your computer and use it in GitHub Desktop.
Same thing in ruby
Infinity = 1.0/0
SAVINGS_INCOME_TAX_200910 = [[0, 6475], [0.1, 8915], [0.2, 43875], [0.4, Infinity]]
INCOME_TAX_200910 = [[0, 6475], [0.2, 43875], [0.4, Infinity]]
def tax(income, bands=INCOME_TAX_200910)
rate, threshold = bands.first
if income <= threshold
rate * income
else
lowered_remaining_bands = bands[1..-1].map {|r, t| [r, t - threshold]}
rate * threshold + tax(income - threshold, lowered_remaining_bands)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment