Created
September 22, 2011 10:08
-
-
Save flq/1234461 to your computer and use it in GitHub Desktop.
the tax thingy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public decimal GetTaxes(decimal salary) | |
{ | |
decimal tax = 0; | |
var progressiveTaxation = new[] { 0.1m, 0.14m, 0.23m, 0.3m, 0.33m, 0.45m }; | |
var progressionSlices = new[] { 5070 - 0, 8660 - 5070, 14070 - 8660, 21240 - 14070, 40230 - 21240, decimal.MaxValue }; | |
var progression = 0; | |
while (salary > 0) | |
{ | |
var taxedSlice = salary - progressionSlices[progression] > 0 ? progressionSlices[progression] : salary; | |
tax += taxedSlice * progressiveTaxation[progression]; | |
salary -= taxedSlice; | |
progression++; | |
} | |
return tax; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yeah, looks unbeatable