Find An Equation that Evaluates to 4 and 6

62 Views Asked by At

I am a student writing a program to compute four numbers {10, 10, 10, 10} with three operators (e.g., "+-/" "++*", etc.) that evaluate to numbers 0-9.

My program evaluates multiple expressions that equal 0-9, except for numbers 4 and 6.

An example is: (10*10)/(10+10) = 100/20 = 5 .

Can someone show me the equation (or tell me how to get to the answer) for numbers 4 and 6? I think if I know the equation, I would know what's wrong with my code. I would much appreciate it.

Edit: My calculation for computing 7 is incorrect.

2

There are 2 best solutions below

3
On BEST ANSWER

I wrote a Python script, with 3 operators and 4 10‘s you can only have:

(0, ‘10-10')
(1, '10/10‘)
(2, '10/10+10/10‘)
(3, '(10+10+10)/10‘)
(5, '10*10/(10+10)')
(8, '10-(10+10)/10')
(9, '(10*10-10)/10‘)

However you can get all digits using 3s.

(0, ‘3-3')
(1, '3/3‘)
(2, '(3+3)/3‘)
(3, '(3+3+3)/3')
(4, '(3+3*3)/3')
(5, '3+(3+3)/3')
(6, '3+3')
(7, '3+3+3/3')
(8, '3*3-3/3‘)
(9, ‘3*3‘)

Solutions using all four numbers

10s

(0, '(10+10+10)%10')
(1, '(10+10-10)/10')
(2, '(10+10)/10%10‘)
(3, '(10+10+10)/10‘)
(5, '10*10/(10+10)')
(8, '10-(10+10)/10')
(9, '10-10/10%10')

4s

(0, '(3+3+3)%3')
(1, '(3+3-3)/3‘)
(2, '(3+3)/3%3‘)
(3, '(3+3+3)/3')
(4, '(3+3*3)/3‘)
(5, '3+(3+3)/3')
(6, '3+3+3-3')
(7, '3+3+3/3')
(8, '3*3-3/3‘)
(9, '(3+3-3)*3‘)
0
On

If we allow addition, subtraction giving a non-negative, multiplication and exact division, we can generate

  • with two operands $10$: $0, 1, 20, 100$,

  • with three operands $10$: $0, 2, 9, 10, 11, 30, 90, 110, 200, 1000$,

  • with four operands $10$: $0, 1, 3, 5, 8, 9, 10, 11, 12, 19, 20, 21, 40, 80, 90,100, \\110, 120, 190, 210, 300, 900, 990, 1010, 1100, 2000, 10000,$

  • with two pairs of two operands: $0, 1, 2, 5, 19, 20, 21, 40, 80, 99, 100, 101, 120, 200, 400, 2000, 10000$.

This exhausts all possibilities.