Skip to content

Instantly share code, notes, and snippets.

@sionide21
Created June 30, 2012 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sionide21/3024123 to your computer and use it in GitHub Desktop.
Save sionide21/3024123 to your computer and use it in GitHub Desktop.
Taxes Estimator 2012
SINGLE_RATES = {8700 => 0.10, 35350 => 0.15, 85650 => 0.25, 178650 => 0.28, 388350 => 0.33, Float::INFINITY => 0.35}
MARRIED_RATES = {17400 => 0.10, 70700 => 0.15, 142700 => 0.25, 217450 => 0.28, 388350 => 0.33, Float::INFINITY => 0.35}
def taxes(amt, rates=SINGLE_RATES)
last_cap = 0
taxes = 0
rates.each do |cap, rate|
taxable = amt - last_cap
if taxable > 0
taxes += [cap, taxable].min * rate
end
last_cap = cap
end
taxes
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment