# Write twenty-four from four numbers

Write 24 using the four numbers 1, 3, 4, 6 and basic arithmetic.

Explanations:

1. The given are numbers, not digits, so you can't group them using decimal notation. For example, you can't create the number 6431.

2. Only one occurrence of each number is allowed. For example, you can't write $24 = 6 + 6 + 6 + 6$.

3. All numbers have to be used.

4. Basic arithmetic means only the 4 operations: $+$, $-$, $\times$, $/$. Also parentheses $(\dots)$ are allowed to set the order of operations.

• I have a feeling the solution has something to do with decimals and not just integers, but that's as far as I've gotten so far. – Doorknob Jun 9 '14 at 16:45
• I had this puzzle once, when I was in grade 9 at a math camp. – Joe Z. Jun 9 '14 at 17:49
• @klm123, Why not just bruteforce it? – Pacerier Jun 9 '14 at 22:12
• Is there a way to generalize this problem? By the way, I've seen this question asked in Hacking:the art of exploitation – Gabriel Romon Jun 25 '14 at 16:53
• @G.T.R, I have no idea what do you mean by generalization of such type of problem, which have unique and unusual (in some psychological sense) answer. – klm123 Jun 25 '14 at 18:35

$\dfrac{6}{1 - \frac{3}{4}}$.

This simplifies to $\frac{6}{1/4}$, which becomes $6 \cdot 4$, which becomes $24$.

• So there's a 5th rule about order of operations? – Jason Jun 9 '14 at 23:46
• parentheses are used to define order of operations :-) – mau Jun 10 '14 at 13:53
• @Jason, that's a valid question. I corrected the condition to allow them explicitly. – klm123 Jun 10 '14 at 17:33

This boils down to the same solution as Kevin's, but uses Reverse Polish notation.

6   1   3   4   /   -   /   =>   24

Notice the elegance of the notation, the lack of brackets, the lack of different sized fonts, the lack of confusing latex markup to write it, the sheer incomprehensibility of what's actually going on, ... uhm, yeah, apart from that, though.

The contents of the stack at each step:

• Excellent answer, but you need to spell out the point: this makes the problem amenable and optimal for recursion without having to add parentheses and worry about nested parsing of open-close parentheses. Recursion simply has to consider all legal string combinations of numbers and the four arithmetic operators. (Order is obviously significant) – smci Jun 4 '17 at 23:54