17
$\begingroup$

Find a mathematical expression that yields the value $2016$ while obeying the following rules:

  • Each of the digits $1,2,3,4,5,6,7,8,9$ is used exactly once
  • Decimal points are allowed
  • You may use brackets "(" and ")" to structure your expression, and to make it well-defined
  • The only allowed mathematical operations are addition (+), subtraction (-), multiplication (*) and division (÷)
  • The only allowed mathematical functions are square-roots and logarithms. Logarithms must be written in the form $\log[b](x)$ to denote the base-$b$ logarithm of number $x$

Note that in particular the following is **not allowed**:
  • Juxtaposition of digits (as juxtaposing 1 and 3 to get "31")
  • other mathematical operations and functions (cube-roots, exponentiation, factorials, absolute values, trigonometric functions, etc)
  • matrices and determinants
  • integration, differentiation, limits
$\endgroup$
13
  • 29
    $\begingroup$ 2016 is too easily factorable for this to be a challenge. $\endgroup$
    – user88
    Mar 6, 2016 at 19:48
  • 3
    $\begingroup$ Some more restrictive rules could be imposed. $\endgroup$ Mar 6, 2016 at 20:18
  • 4
    $\begingroup$ What do you mean by "decimal points are allowed"? Do you mean numbers like $.7$? Also, you should specify whether or not $0$ is allowed. $\endgroup$ Mar 6, 2016 at 20:37
  • 4
    $\begingroup$ All the Perry-style solutions proposed so far use only the operations $+$, $-$, and $\times$. There are $\frac{3^8 \cdot 16!}{8! \cdot 9!} = 9,382,230$ such expressions using the digits $1$ to $9$ in sequence. I suppose one could just simple-mindedly calculate the values of all of them, and see which ones work out to be $2016$. It's easily computationally feasible, but it might be fun to try to think of a less stupid method! Or else, it might be idiotic to become obsessed with such a silly idea. I'm trying to make myself not think about it now. Damn. :) $\endgroup$ Mar 6, 2016 at 23:29
  • 12
    $\begingroup$ I just want to point it out that if you check this wonderful answer you will realize that there are 366 possible combinations of 2016 using solely the "-", "+" and "*" operations. It happens that 2016 is a leap year, which means you can have 1 solution for every day. I find this more satisfying than I should. $\endgroup$ Mar 8, 2016 at 21:42

18 Answers 18

48
$\begingroup$

((9 * 8 * 7 * 6 * 2) / 3) + 5 - 4 - 1

And three more à la Perry

1 * (2 - 3 + 4 - 5 + 6) * 7 * 8 * 9
(1 + 2 + 3 + 4 + 5 + 6 + 7) * 8 * 9
1 * (2 + 3 + 4 + 5) * 6 * (7 + 8 + 9)

$\endgroup$
3
  • 27
    $\begingroup$ I particularly like the second of those three 'monotonic' solutions! $\endgroup$ Mar 6, 2016 at 20:22
  • 2
    $\begingroup$ the third reminds me of something... $\endgroup$
    – JMP
    May 20, 2016 at 13:06
  • 8
    $\begingroup$ New year's $2017$ update: $$1+(2-3+4-5+6)\cdot 7\cdot 8\cdot9$$ $$1+(2+3+4+5)\cdot 6\cdot (7+ 8+9)$$ $\endgroup$ Jan 26, 2017 at 19:37
49
$\begingroup$

(((1 - 2) x (3 + 4)) + 5 + 6) x 7 x 8 x 9

$\endgroup$
1
  • 13
    $\begingroup$ nice monotonicity $\endgroup$ Mar 6, 2016 at 14:48
37
$\begingroup$

For those interested, here is a brute-forced list of all "monotonic" expressions that use addition, subtraction, multiplication, and division. There's 835 of them in total.

EDIT: For extra fun, here is a list of the 1,151 expressions that use 9 through 1 in order!

$\endgroup$
7
  • 2
    $\begingroup$ LOL! It's quite worrying how much this pleases me. :) By the way, what programming language did you use? $\endgroup$ Mar 7, 2016 at 12:49
  • $\begingroup$ @CalumGilhooley I just used a small C# program. I would also include logarithms, but it makes the program explode. $\endgroup$ Mar 7, 2016 at 13:03
  • $\begingroup$ It would also be funny looking at monotonic expressions allowing the base 10 notation, like (12+345)*6-... I wonder if there is any giving 2016! $\endgroup$ Mar 8, 2016 at 9:28
  • 1
    $\begingroup$ e.g. 9*(8+6*7*5+4)-3+21 $\endgroup$ Mar 8, 2016 at 12:22
  • 1
    $\begingroup$ @PietroMajer Sadly, that would also make the program explode. $\endgroup$ Mar 9, 2016 at 12:49
19
$\begingroup$

Since 2016 is a multiple of 504 = 7 x 8 x 9, any expression using 1, 2, 3, 4, 5, 6 that evaluates to 4 can just multiply those three afterwards and evaluate to 2016.

So all the following are correct:

9 x 8 x 7 x (6 - 5) x 4 x (3 - 2) x 1 = 2016
9 x 8 x 7 x (6 - 5) x 4 + 3 - 2 - 1 = 2016
9 x 8 x 7 x 6 / (5 + 4) x (3 + 2 + 1) = 2016

There are probably at least fifty more variations that I didn't bother to work out.

$\endgroup$
1
  • 1
    $\begingroup$ Similarly, anything with 9 x 8 x 7 x 4 plus any combination that equals zero will work as well. $\endgroup$
    – ale10ander
    Apr 18, 2016 at 4:18
15
$\begingroup$

I have found all 3,020 expressions satisfying the given restrictions along with four others:

  • The digits 1-9 must be in order.
  • You are not allowed to take the square root of $1$ or $0$. Without this restriction we could have arbitrarily complex expressions.
  • Every subexpression must have a rational value. This excludes expressions that involve terms like $\log[2]\sqrt{2}=\frac{1}{2}$. Without this restriction we could have arbitrarily complex expressions.
  • Decimal points are not allowed, since it is not clear how we are allowed to use them.

My algorithm works as follows. I compute a table of values $\mathtt{terms}$, where each element $\mathtt{terms}[i,j]$ represents the possible values of a subexpression starting at the $i$-th number and spanning $j$ numbers. As an example, take the expression:

$$((1 - (2 \times (3 - 4) + 5)) + 6) \times 7 \times 8 \times 9$$

The term $3-4$ is associated with $\mathtt{terms}[3,2]$, and the term $7 \times 8 \times 9$ is associated with $\mathtt{terms}[7,3]$. The entire expression is associated with $\mathtt{terms}[1,9]$, and the individual numbers are associated with $\mathtt{terms}[*,1]$

Each $\mathtt{terms}[i,j]$ is a list of key-value pairs: the keys are the values of that subexpression, and the values are the ways of reaching that value. For example:

$$ \begin{align} \mathtt{terms}[1, 2] = \{\quad 3 &\to \{1+2\ (1)\},\\ -1 &\to \{1-2\ (1)\}, \\ 2 &\to \{1 \times 2\ (1)\}, \\ \tfrac{1}{2} &\to \{1 \div 2\ (1)\} \quad\} \end{align} $$

A quick note: for binary operators (all of them except the square root) I store the operator, the left and right-hand operands, and the size of the left operand. The last one is necessary in the second part of the algorithm, and above and below it is shown in parenthesis. Another example:

$$ \begin{align} \mathtt{terms}[1, 3] = \{\quad 6 &\to \{1+5\ (1),\ 1\times 6\ (1),\ 3+3\ (2),\ 2\times 3\ (2)\},\\ 0 &\to \{1+(-1)\ (1),\ 3-3\ (2),\ \sqrt{0}\},\\ 1 &\to \{3\div 3\ (2),\ \log[3](3)\ (2),\ \sqrt{1}\}, \\ \vdots \end{align} $$

A few notes:

  • For all operators, only the values of the operands are stored instead of the entire subexpressions. This is what makes this method efficient.
  • Square roots do not need a length stored with them, since they apply to a single subexpression.
  • The restriction on square roots of $0$ and $1$ is not applied at this stage (they add at most a constant overhead).

The algorithm that computes $\mathtt{terms}$ is as follows:

  • Loop over $\ell=1\ldots 9$:
    • Loop over $i=1\ldots 10 - \ell$:
      • If $\ell = 1$, initialize $\mathtt{vals}=\{i \to \{i\}\}$.
      • Otherwise, initialize $\mathtt{vals}=\{\}$ and loop through $k=1\ldots \ell-1$:
        • Get the possible values of the left-hand and right-hand operands. These are: $$\begin{align}\mathtt{LHS}&=\mathtt{terms}[i,k] \\ \mathtt{RHS}&=\mathtt{terms}[i+k,\ell-k]\end{align}$$
        • Construct all possible terms: $$a\circ b\ (k);\ a\in\mathtt{LHS},\ b\in\mathtt{RHS},\ \circ\in\{+,-,\times,\div,\log\}$$
        • Add to $\mathtt{vals}$ all terms that result in a rational value.
      • Repeatedly take a the square root of each term in $\mathtt{vals}$. If the result is a rational value, add it to $\mathtt{vals}$.
      • Set $\mathtt{term}[i,\ell]=\mathtt{vals}$.

Next we traverse $\mathtt{terms}$ in reverse order. Starting with $\mathtt{terms}[1,9]$ we get all the ways to make $2016$, then recursively get all the ways to make each subexpression, ignoring $\sqrt{1}$ and $\sqrt{0}$. This results in a list of 32,282 expressions. I then normalize the expressions using the following transformations:

$$ \begin{align} \cdots+(x_1+\cdots+x_n)+\cdots &\to \cdots+x_1+\cdots+x_n+\cdots \\ \cdots\times(x_1\times\cdots\times x_n)\times\cdots &\to \cdots\times x_1\times\cdots\times x_n\times\cdots \\ \cdots+(x-y)+\cdots &\to ((\cdots+x)-y)+\cdots \\ \cdots\times(x\div y)\times\cdots &\to ((\cdots\times x)\div y)\times\cdots \end{align} $$

This prevent us from counting expressions like $(1+2)+3$ and $1+(2+3)$ as different. After this step, there are only 3,020 distinct expressions. The full list is available here. Note that this list uses Mathematica notation: $\times\to\mathtt{*},$ $\div\to\mathtt{/},$ $\sqrt{x}\to\mathtt{Sqrt[}x\mathtt{]},$ and $\log[b](x)\to\mathtt{Log[}b\mathtt{,}x\mathtt{]}$.

Of particular note are the expressions:

(1+Log[2,Log[3,4+5]])*6*7*8*Sqrt[9]
(1+Log[2,Log[3,4+5]+6])*7*8*9

(i.e:)

$$ (1+\log[2](\log[3](4+5)))\times 6\times 7\times 8\times\sqrt{9} \\ (1+\log[2](\log[3](4+5)+6))\times 7\times 8\times 9 $$

Each of which use $\log$ twice, with two different bases!

$\endgroup$
0
12
$\begingroup$

Using all operations and functions

$9 \cdot 8 \cdot 7 \cdot \sqrt{4} \cdot \log_2(1+\frac{6}{5-3})$

$\endgroup$
12
$\begingroup$

A variation on Jon Mark Perry's answer:

(1 + 2 - 3 - 4) x (5 - 6) x 7 x 8 x 9

I wonder how many such 'monotonic' solutions there are?

$\endgroup$
1
  • 1
    $\begingroup$ LegionMammal got you covered ;) $\endgroup$
    – DrunkWolf
    Mar 7, 2016 at 19:51
11
$\begingroup$

How about:

$(9 \cdot 8 \cdot 7)(6 - 2)\frac{5 - 3}{\sqrt4}\times1$

$\endgroup$
0
11
$\begingroup$

I had code lying around that solves this exact problem, and the first thing it spat out was:

(1 + 2 + 3 + 4 + 5 + 6 + 7) * 8 * 9

$\endgroup$
3
  • $\begingroup$ This is very nice, but aside from the personal background, it is a subset of Pietro Majer’s answer from a day earlier; it seems a bit odd to accept this in preference to that. $\endgroup$ Mar 9, 2016 at 16:16
  • $\begingroup$ @PeterLeFanuLumsdaine I agree - I didn't notice the equivalence to one of the answers in Pietro's answer when I wrote it. I probably should have done. After posting, I did find it in the brute forced list linked to in LegionMammal978's answer, but it's buried way down the list in the middle. I think it's the nicest and simplest answer of any of them. $\endgroup$
    – rjmunro
    Mar 10, 2016 at 10:45
  • $\begingroup$ @Peter LeFanu Lumsdaine: I see, and I follow your advice. $\endgroup$
    – Gamow
    Mar 11, 2016 at 15:51
9
$\begingroup$

A simple answer:

1·2·3·6·7·8 + 0·4·5·9 = 2016; based off of the fact that 2016=25·32·7.

If that feels too cheaty, then try this:

1·2·3·6·7·8 + 4 + 5 - 9 = 2016

$\endgroup$
5
  • 4
    $\begingroup$ you can't use 0... $\endgroup$
    – JMP
    Mar 6, 2016 at 15:01
  • $\begingroup$ @JonMarkPerry Where does it say that? $\endgroup$ Mar 6, 2016 at 15:01
  • 1
    $\begingroup$ implicitly in the Q $\endgroup$
    – JMP
    Mar 6, 2016 at 15:02
  • 1
    $\begingroup$ @JonMarkPerry See my second version if you want to be satisfied. $\endgroup$ Mar 6, 2016 at 15:03
  • 7
    $\begingroup$ Note that log(1)=0, so you could easily convert your first expression into something that works, e.g. log[4](1)*5*9 $\endgroup$
    – Floris
    Mar 7, 2016 at 4:52
8
$\begingroup$

My favorite so far:

9 * 8 * 7 * 6 * (5 - 4) / 3 * 2 * 1

Had factorials been allowed, I'd have preferred

9 * 8 * 7 * 6! / 5! * 4 / 3 / 2 * 1

$\endgroup$
1
  • $\begingroup$ Why would you have preferred the second? The first is so much more elegant. $\endgroup$
    – minseong
    Mar 21, 2017 at 15:41
6
$\begingroup$

In the spirit of the question, I felt it was time for a solution that includes all allowed operations, including a decimal point, a logarithm and a square root (using the hint from Joe Z about the general structure of a solution):

9. * 8 * 7 * (-6 + 5 + log[2](4) * 3 / √1)

or, with a small tweak from the comment by @f'', this:

9 * 7 * 4 * (2 - 3 / log[5](√((1 + .6) / 8)))

which not only has +, -, *, /, decimal, sqrt, and log, but makes every operation "do something"

$\endgroup$
0
5
$\begingroup$

Here's mine:

2016 = (9 * 8 * 7 * 4) + 5 * (1 + 2 + 3 - 6)

The first expression is just the factorization of 2016, the rest is just to spend the other digits in a zero-sum.

$\endgroup$
5
$\begingroup$

((8 + 6 + 3 + (2 * 7)) * (9 + 4) * 5) + 1 = 2016

$\endgroup$
4
$\begingroup$

This is my answer:

1 * 2 * 3 * 4 * 6 * 7 * 8 / (9-5)

$\endgroup$
4
$\begingroup$

Hehe. Whenever logarithms are allowed:

$$ \log_\frac12\left[\log_{8+7+6-5-4-3}\sqrt{\sqrt{\cdots{\sqrt{\sqrt{9\,}\,}\,}}\,} \right] $$

with a total of 2016 square roots.

$\endgroup$
3
$\begingroup$

The truly amazing way to get 2016 is

${10 \times 9 \times 8 \times 7 \times 6} \over {5 + 4 + 3 + 2 + 1}$

Unfortunately, that doesn't answer the question. But it's close enough, you can fix it:

${9 \times 8 \times 7 \times 6} \over {.5 + .4 + .3 + .2 + .1}$

But that one is less truly amazing imho.

$\endgroup$
2
$\begingroup$

Let's put the given numbers as follows. $ (\frac{6+3+1}{2\times5}) \times4\times8\times7\times9=2016$

$\endgroup$

Your Answer

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

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