4
\$\begingroup\$

If elected president, Donald Trump plans to implement a system of four income tax brackets (full details can be found on his website here). Your job is to take two inputs, annual income and filing status (single, married, or head of household), and output the income tax that must be paid.

Income Tax Brackets

The Trump Tax

(We are only interested in the income tax rate; you can ignore the long-term capital gain rate).

Note that income taxes are computed using marginal rates — that is, you only pay the bracket rate for the portion that exceeds the bracket's minimum amount.

For example, a single filer making $45,000 a year would pay 0% on the first $25,000, and 10% on the $20,000 after that, for a total of $2,000 in taxes.

A married couple filing jointly for $500,000 would count 25% only on the amount exceeding $300,000, and add $45,000 to that to account for the income earned in lower brackets (which is 10% of $50,000 plus 20% of $200,000).

Input/Output

Input/Output is flexible. You can take input as command-line arguments or prompt for inputs, as well as either return or output/display the result. The inputs and output must be numbers, but you are free to determine what the second number would be (for example, 0 = single, 1 = married, 2 = head of household). Just don't be ridiculous - Single digit numbers only.

Also, functionality for decimal inputs (i.e. including cents) is undefined, so you only have to worry about integer inputs. For your output, you may either output a decimal value or round it to the nearest whole number.

Test Cases

Although the second number's range can be flexible as stated above, these test cases assume that 0 = single, 1 = married, and 2 = head of household:

25000  0 --> 0
37501  2 --> 0.1 or 0
51346  1 --> 134.6 or 135
75000  0 --> 7500
75000  1 --> 2500
123456 2 --> 13441.2 or 13441
424242 0 --> 91060.5 or 91061
\$\endgroup\$
10
  • 1
    \$\begingroup\$ Closely related \$\endgroup\$
    – Alex A.
    May 14, 2016 at 0:26
  • \$\begingroup\$ You are advised to wait for at least a day, preferably two days, before posting your question. \$\endgroup\$
    – Leaky Nun
    May 14, 2016 at 0:37
  • 3
    \$\begingroup\$ @KennyLau By "don't be ridiculous", how about single digit numbers only... \$\endgroup\$
    – Timtech
    May 14, 2016 at 1:26
  • 1
    \$\begingroup\$ Because that would be too broad. Even 0, 1, 2 can be considered "program information" \$\endgroup\$
    – Leaky Nun
    May 14, 2016 at 2:07
  • 10
    \$\begingroup\$ Does the tax amount really jump up when you cross a boundary? I thought that tax brackets work that you pay 0% for the first $25000 if single, then 10% for the portion between 25000 and 50000, and so on. \$\endgroup\$
    – xnor
    May 14, 2016 at 2:07

4 Answers 4

7
\$\begingroup\$

Pyth, 32 bytes

*c@_j270588 6shS,6ca0tQ*12500E20

Test suite.

  • 2 = single
  • 4 = married
  • 3 = head of household

Some ridiculous encodings:

Previous 6-byte:

JQ.vCE

Test suite.

  • 74892585093965377905208487730659359537614936740881725652453863997600444976 = single
  • 74892585093965377905208487730659359537614936740881725652668629404830675504 = married
  • 74892585093965377905208487730659359537614936740881725652526490039149933104 = head of household

Encodes the whole program into the second number.

Previous 24-byte:

JjE^T6*c@tJhS,7shctQhJ20

Test suite.

  • 25000000000000000000002000004000004000004000004000005 = single
  • 50000000000000000000002000004000004000004000004000005 = married
  • 37500000000000000000002000004000004000004000004000005 = head of household

Previous 26-byte:

*c@_j270588 6shS,6ca0tQE20

Test suite.

  • 25000 = single
  • 50000 = married
  • 37500 = head of household
\$\endgroup\$
1
  • \$\begingroup\$ OP has updated to specify "single digit numbers only" \$\endgroup\$
    – Downgoat
    May 14, 2016 at 2:04
5
\$\begingroup\$

TI-Basic, 34 32 bytes

Variable F is filing status where 2 = single, 3 = head of household, and 4 = married. Also, E is the scientific E.

Prompt I,F:4I/F>E5{.5,1,3:.1Isum(Ans{1,1,.5

Explanation:

Prompt I,F          get input into I and F
4I/F               converts the income so it fits the married tax bracket
    >E5{.5,1,3     gives a list like {0 0 0}, {1 0 0}, {1 1 0}, or {1 1 1} based on bracket
   sum(Ans{1,1,.5  Multiplies previous list by {1 1 .5} and sums it
.1I                Previous number is 0 1 2 or 2.5, so multiply by .1 and then by income
\$\endgroup\$
5
  • \$\begingroup\$ I'm not horribly familiar with TI-Basic, but would newlines instead of colons save bytes, or just displayable characters? \$\endgroup\$
    – Zwei
    May 14, 2016 at 1:53
  • \$\begingroup\$ Which TI-Basic? 83? 84? Nspire? \$\endgroup\$ May 14, 2016 at 3:09
  • \$\begingroup\$ what is the scientific E? \$\endgroup\$ May 14, 2016 at 7:51
  • 1
    \$\begingroup\$ @LeifWillerts tibasicdev.wikidot.com/e-ten \$\endgroup\$
    – Timtech
    May 14, 2016 at 13:26
  • \$\begingroup\$ duh, of course! \$\endgroup\$ May 17, 2016 at 8:28
1
\$\begingroup\$

JavaScript (ES6), 52 bytes

(i,m,g=b=>i>b&&(i-=b)/10)=>g(m=15e4/m)+g(m)+g(m*4)/2

Key:

6 = Single
3 = Married
4 = Head
\$\endgroup\$
0
\$\begingroup\$

Stax, 24 bytes

ï¥Ωü+àqGZvwJ╫BMwbë↕)bÿ╠»

Run and debug it

\begin{align}\text{Single}&\mapsto 2\\ \text{Married}&\mapsto4\\ \text{Head of Household}&\mapsto3 \end{align}

Outputs a fraction.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.