# Federal income tax calculator for procrastinators

Today is Tax Day!

Oops.

So you're probably still completing your return and need a calculator for when you get to Line 44.

Given an input of taxable income (US$, accurate to 2 decimal places) and a string representing filing status, output the amount of tax (also US$ to 2 decimal places).

Filing status will be one of S, MFJ, QW, MFS, or HH for Single, Married Filing Jointly, Qualified Widow(er), Married Filing Separately or Head of Household, respectively.

### Example Inputs:

0.00 S
10000.00 MFJ
100000.00 MFS
1000000.00 QW


### Example Outputs corresponding to above inputs:

0.00
1000.00
21525.75
341915.90


# Summary of tax tables.

### Married Filing Jointly and Qualified Widow(er)

Income Interval Tax [ $0,$18450] 10% ( $18450,$74900] $1845 + 15% of the excess over$18450 ( $74900,$151200] $10312.50 + 25% of the excess over$74900 ($151200,$230450] $29387.50 + 28% of the excess over$151200 ($230450,$411500] $51577.50 + 33% of the excess over$230450 ($411500,$464850] $111324 + 35% of the excess over$411500 ($464850,$∞] $129996.50 + 39.6% of the excess over$464850

### Head of Household

Income Interval Tax [ $0,$13150] 10% ( $13150,$50200] $1315 + 15% of the excess over$13150 ( $50200,$129600] $6872.50 + 25% of the excess over$50200 ($129600,$209850] $26722.50 + 28% of the excess over$129600 ($209850,$411500] $49192.50 + 33% of the excess over$209850 ($411500,$439000] $115737 + 35% of the excess over$411500 ($439000,$∞] $125362 + 39.6% of the excess over$439000

### Single

Income Interval Tax [ $0,$9225] 10% ( $9225,$37450] $922.50 + 15% of the excess over$9225 ( $37450,$90750] $5156.25 + 25% of the excess over$37450 ( $90750,$189300] $18481.25 + 28% of the excess over$90750 ($189300,$411500] $46075.25 + 33% of the excess over$189300 ($411500,$413200] $119401.25 + 35% of the excess over$411500 ($413200,$∞] $119996.25 + 39.6% of the excess over$413200

### Married Filing Separately

Income Interval Tax [ $0,$9225] 10% ( $9225,$37450] $922.50 + 15% of the excess over$9225 ( $37450,$75600] $5156.25 + 25% of the excess over$37450 ( $75600,$115225] $14693.75 + 28% of the excess over$75600 ($115225,$205750] $25788.75 + 33% of the excess over$115225 ($205750,$232425] $55662 + 35% of the excess over$205750 ($232425,$∞] $64998.25 + 39.6% of the excess over$232425

• I'd like to see "golf the entire functionality of TurboTax" – qwr Apr 20 '16 at 2:39
• @qwr I don't think golfing works well with the whole "fix it every year" that tax code has to be – CAD97 Apr 20 '16 at 2:48
• @CAD97 Nonsense, even this problem is year dependent! – qwr Apr 20 '16 at 2:56

## Python 3, 427382317309308 275 bytes

-45 bytes by figuring ternary expression out (wow that's a long line); thanks Maltysen

-65 bytes, now with iteration for DRYer code!

-8 bytes by in-lining tuple variables; thanks Majora

-1 byte by using a dict rather than ternary chain; thanks again Maltysen

-33 bytes by reusing MFS step as half of MFJ/QW and calculating tax an order of magnitude larger; thanks Neil

def f(i,s):
t=i;k={'MFS':(9225,28225,38150,39625,90525,26675),'S':(9225,28225,53300,98550,222200,1700),'HH':(13150,37050,79400,80250,201650,27500)}
for x in range(6):
i-=k[s][x]if s in k else k['MFS'][x]*2
if i>0:t+=(.5,1,.3,.5,.2,.46)[x]*i
return'{:.2f}'.format(t*.1)


If I had been thinking I would have made the function signature t(a,x), but I guess I'll stick with function(income, status).

When code is barely undertstood by the writer, is that when you win at golf?

• you can save by changing the ifs into a series of ternaries and having only one a,b,c,d,e,f= – Maltysen Apr 20 '16 at 0:12
• @Maltysen And now since I figured out how to iterate to save repetition of taxation, I only have to assign the tuple :) – CAD97 Apr 20 '16 at 0:37
• You can shave off 10 bytes by replacing c and r with the literal tuple, because they are only used once. (tested, working; even works with the long c line) – Majora320 Apr 20 '16 at 0:49
• you can prolly save more with either dicts or indexing and slicing. – Maltysen Apr 20 '16 at 0:58
• "When code is barely undertstood by the writer, is that when you win at golf". Almost. The next step is to port your code to pyth :) – Digital Trauma Apr 20 '16 at 2:47

## JavaScript (ES6), 223 bytes

(i,s)=>(({MFS:a=[x=9225,y=28225,38150,39625,90525,26675],S:[x,y,53300,98550,222200,1700],HH:[13150,37050,79400,80250,201650,27500]}[s]||a.map(b=>b*2)).reduce((t,b,j)=>t+((i-=b)>0&&i*[.5,1,.3,.5,.2,.46][j]),i)*.1).toFixed(2)


Basically a port of CAD97's Python answer, but I saved 4 bytes by multiplying the tax by 10 during the calculation and 11 bytes by reducing the duplication in the tax bands.

• @DigitalTrauma Oops I don't develop on the machine on which I have PPCG open so sometimes I typo when copying the code across. (The beauty of Code Golf is that I want to copy as little code as possible!) – Neil Apr 20 '16 at 16:41
• Good. Works for me now in both firefox and chrome. – Digital Trauma Apr 20 '16 at 16:46