Skip to content

Instantly share code, notes, and snippets.

@mythz
Created September 24, 2011 04:19
Show Gist options
  • Select an option

  • Save mythz/1238962 to your computer and use it in GitHub Desktop.

Select an option

Save mythz/1238962 to your computer and use it in GitHub Desktop.
Calculate Israel's fast with C#
using System;
namespace FastIsraelTaxCalculator
{
class MainClass
{
static readonly string[] DefaultAmounts = new[] { "5000", "5800", "9000", "15000", "50000" };
public static void Main (string[] args)
{
if (args.Length == 0) args = DefaultAmounts;
foreach (var amt in args)
{
int salary = int.Parse(amt);
Console.WriteLine("Tax Rate for {0} is {1}", salary, CalcTaxFast(salary));
}
}
public static decimal CalcTaxFast(int salary)
{
const int band1 = 5070;
const decimal rate1 = 0.10m;
const int band2 = 8660;
const decimal rate2 = 0.14m;
const int band3 = 14070;
const decimal rate3 = 0.23m;
const int band4 = 21240;
const decimal rate4 = 0.30m;
const int band5 = 40230;
const decimal rate5 = 0.33m;
const decimal rate6 = 0.45m;
const decimal bandTax1 = band1 * rate1;
const decimal bandTax2 = (band2 - band1) * rate2 + bandTax1;
const decimal bandTax3 = (band3 - band2) * rate3 + bandTax2;
const decimal bandTax4 = (band4 - band3) * rate4 + bandTax3;
const decimal bandTax5 = (band5 - band4) * rate5 + bandTax4;
if (salary > band5)
return (salary - band5) * rate6 + bandTax5;
if (salary > band4)
return (salary - band4) * rate5 + bandTax4;
if (salary > band3)
return (salary - band3) * rate4 + bandTax3;
if (salary > band2)
return (salary - band2) * rate3 + bandTax2;
if (salary > band1)
return (salary - band1) * rate2 + bandTax1;
return salary * rate1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment