Skip to content

Instantly share code, notes, and snippets.

Created September 25, 2011 21:08
Show Gist options
  • Select an option

  • Save anonymous/1241154 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/1241154 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Sal = {0}, Taxes = {1}", 5000, Taxes(5000));
Console.WriteLine("Sal = {0}, Taxes = {1}", 5800, Taxes(5800));
Console.WriteLine("Sal = {0}, Taxes = {1}", 9000, Taxes(9000));
Console.WriteLine("Sal = {0}, Taxes = {1}", 15000, Taxes(15000));
Console.WriteLine("Sal = {0}, Taxes = {1}", 50000, Taxes(50000));
Console.ReadLine();
}
static decimal Taxes(decimal sal)
{
Tuple<decimal, decimal>[] rates =
{
new Tuple<decimal, decimal>(0m, 0.1m),
new Tuple<decimal, decimal>(5070m, 0.14m),
new Tuple<decimal, decimal>(8660m, 0.23m),
new Tuple<decimal, decimal>(14070m, 0.30m),
new Tuple<decimal, decimal>(21240m, 0.33m),
new Tuple<decimal, decimal>(40230m, 0.45m)
};
return rates.Reverse().Select(bracket =>
{
var amt = Math.Max(0, sal - bracket.Item1);
sal -= amt;
return amt * bracket.Item2;
}).Sum();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment