Is there a way you can get the number $6$ from the numbers $6, 7, 8$, and $9$ using only addition, subtraction, multiplication, and division, without combining two numbers e.g. using the $6$ and $7$ to create $67$. You may use parentheses and you can have to use each of the $4$ numbers once.
How to get $6$ from the numbers $\{6, 7, 8, 9\}$ using only addition, subtraction, division, and multiplication.
275 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail AtThere are 3 best solutions below
On
Use Polish notation. Four numbers, each used only once. Three operators (out of 4). The sequence order matters. Operators can be repeated. That would be 20 groups of 3 operators (taken from 4, with possible repetitions), {+, -, ×}, {+, -, :}, {+, ×, :}, {-, ×, :}, {+, +, -} , {+, + ×} , {+, +, :}, {-, -, +}, {-, -, ×}, {-, -, :}, {×, ×, +}, {×, ×, -}, {×, ×, :}, {:, :, +}, {:, :, -}, {:, :, ×}, {+, +, +}, {-, -, -}, {×, ×, ×}, {:, :, :}. Now, for each group there are at most 6 permutations of these operators if they are distinct (or less if some operators are repeated). The four numbers are distinct, so we have 24 permutations in each case.
To be optimistic, you have at most 24 × 20 × 6 = 2880 Polish sequences to check.
I will do the first one.
+++6789 = 30 (not a 6). Well, you have at most 2879 more to go (a bit less actually). Good luck.
Edit. Following the comments, this analysis is incomplete , but a systematic approach (for the purpose of implementing a search algorithm) is possible. It won't be done here.
On
Below python code generates all possible positive integer combinations of these numbers together with all possible combinations of signs in all possible places with the help of the reverse polish notation. It is worth pointing out that we can't achieve certain negative results (e.g. $-30=-6-7-8-9$) as we cannot put minus at the beginning. However all possible combinations ($4! \cdot C_3 \cdot 4^3 = 24 \cdot 5 \cdot 256 = 7680$ to be exact) are checked quite quickly yielding $127$ positive integer solutions none of which are equal to $6$.
permutations = [[6,7,8,9],[6,7,9,8],[6,8,7,9],[6,8,9,7],[6,9,7,8],[6,9,8,7],
[7,6,8,9],[7,6,9,8],[7,8,6,9],[7,8,9,6],[7,9,6,8],[7,9,8,6],
[8,6,7,9],[8,6,9,7],[8,7,6,9],[8,7,9,6],[8,9,6,7],[8,9,7,6],
[9,6,7,8],[9,6,8,7],[9,7,6,8],[9,7,8,6],[9,8,6,7],[9,8,7,6]]
rpn = [[4,5,6],[3,5,6],[3,4,6],[2,5,6],[2,4,6]]
signs = [lambda x, y: x + y, lambda x, y: x - y, lambda x, y: x * y, lambda x, y: x / y]
stack = []
results = set()
for i in permutations:
for j in rpn:
for a in signs:
for b in signs:
for c in signs:
per = i.copy()
per.insert(j[0], a)
per.insert(j[1], b)
per.insert(j[2], c)
for k in per:
if(type(k) == int):
stack.append(k)
else:
p, q = stack.pop(), stack.pop()
stack.append(k(p,q))
results.add(stack.pop())
results = sorted(results)
for i in results:
if(i == int(i) and i > 0):
print(int(i))
The following disgraceful python code performs an exhaustive search and gives no solutions for 6. Thw closest hit is $6+7/(8*9)\approx 6.097222$ (or $6-7/(8*9)$). You can change line 29,
if K==6:from 6 to any other number to find other solutions. For instance, it finds correctly that $6/(7-9)+8=5$ and $(6+8)/(9-7)=7$. You can also remove the last 3 lines to make it spit out all possible answers. For instance, I believe all solutions for 7 are (with some dupes)I didn't bother with checking if two choices of bracketing resulted in the same expression. In particular, it checks $4!\times 4^3\times 11=16896$ expressions(if the code doesnt terminate first). I hard-coded all possible bracketings because I don't know yet how to code better, but these are all of them because of How many ways are there to put parentheses between $n$ numbers? . It seems like I can learn from this website which solves a very similar problem. Anyway, the code-
You can compile this code on this website.