5
$\begingroup$

There are ten expressions written in the scheme below from left to right and top to bottom. Replace all of the ten distinct letters in the scheme with a single digit between 0 and 9 and make the expressions true. The usual operator precedence rules apply.


$$ \begin{array}{ccccccccccc} \Large\color{red}{\bf F}&+& \Large\color{blue}{\bf H}&-& \Large\color{goldenrod}{\bf C}&×& \Large\color{violet}{\bf A}&+& \Large\color{orange}{\bf E}&=& \Large0\\ -& &+& &÷& &×& &× \\ \Large\color{limegreen}{\bf B}&-& \Large\color{firebrick}{\bf J}&÷& \Large\color{blue}{\bf H}&-& \Large\color{goldenrod}{\bf C}&÷& \Large\color{violet}{\bf A}&=& \Large1\\ +& &-& &-& &-& &- \\ \Large\color{purple}{\bf D}&-& \Large\color{limegreen}{\bf B}&÷& \Large\color{firebrick}{\bf J}&+& \Large\color{dodgerblue}{\bf I}&-& \Large\color{goldenrod}{\bf C}&=& \Large2\\ +& &÷& &+& &+& &÷ \\ \Large\color{orange}{\bf E}&×& \Large\color{purple}{\bf D}&+& \Large\color{green}{\bf G}&-& \Large\color{firebrick}{\bf J}&×& \Large\color{dodgerblue}{\bf I}&=& \Large3\\ +& &+& &×& &-& &- \\ \Large\color{violet}{\bf A}&-& \Large\color{orange}{\bf E}&+& \Large\color{purple}{\bf D}&÷& \Large\color{green}{\bf G}&+& \Large\color{red}{\bf F}&=& \Large4\\ =& &=& &=& &=& &= \\ \Large9& &\Large8& &\Large7& &\Large6& &\Large5 \end{array} $$

Bonus question: If you were to write a computer program to solve this puzzle by brute force, how many cases would you need to check at most?

Hint 1:

No computer is required to solve this.

Hint 2:

You must not assign different digits to different letters.

$\endgroup$
  • 1
    $\begingroup$ Is one of the sets of 'J's intended to be 'B's? $\endgroup$ – frodoskywalker Jan 1 '15 at 10:52
  • 1
    $\begingroup$ Must we assign different digits to different letters? $\endgroup$ – Lopsy Jan 1 '15 at 14:13
  • $\begingroup$ Thanks, just making sure. Also, the answer to the bonus question depends hugely on how you do your brute force. It's 10^10 if you just naively try everything, but it's probably less than 10,000 if you do it right. $\endgroup$ – Lopsy Jan 1 '15 at 15:47
  • 1
    $\begingroup$ I have no idea what you're going for on the bonus question, and neither does anyone else except you. If I were to write a program to brute-force this, it would be a simple backtracking search, starting with the constraints that all the division operations work out. In fact, I just did this, and my program checked 3807921 cases. If I were clever, I could have lopped off many cases by hand. But then it would have taken more than 5 minutes to write and run the program, and it would no longer be "brute force" by any reasonable definition of the term. $\endgroup$ – Lopsy Jan 1 '15 at 17:19
  • 1
    $\begingroup$ This was going to be an interesting puzzle, but the intentionally misleading wording in the name of "lateral thinking" and its interpretation just makes it silly. $\endgroup$ – xnor Jan 2 '15 at 16:19
1
$\begingroup$

With the second hint, it's rather easy: if we assign the same digit to all of the letters then the first row gives $3d - d^2 = 0$ whence $d = 3$ (since $d = 0$ definitely isn't a solution), and then it's just a matter of checking.

(In fact, the fourth row becomes $d^2 + d - d^2 = 3$ which has only one solution).

$\endgroup$
  • $\begingroup$ Good one! How about the bonus question? $\endgroup$ – GOTO 0 Jan 1 '15 at 16:01
  • 1
    $\begingroup$ @GOTO0, the bonus question is ill-defined. I can make easy cases for 3, 4, 10, and 10^10, and less easy cases for certain other values. $\endgroup$ – Peter Taylor Jan 1 '15 at 16:10
  • $\begingroup$ 10^10 cases? Hmm... no bonus for you. But congrats for solving the puzzle. $\endgroup$ – GOTO 0 Jan 1 '15 at 16:19
  • $\begingroup$ Why do you want to assign the same digit to all the letters? $\endgroup$ – David Tonhofer Jan 2 '15 at 11:30
  • $\begingroup$ @DavidTonhofer, "Replace all of the ten distinct letters in the scheme with a single digit" is a very deliberately worded clue. The correct way to word it if the letters had different values would be "Replace each of the ten distinct letters..." $\endgroup$ – Peter Taylor Jan 2 '15 at 11:39
1
$\begingroup$

Semi-stupid exhaustive search demands 10*9*10*9*10 = 99000 checks and finds the single solution.

Anything better?

Program here

solve([A,B,C,D,E,F,G,H,I,J]) :-
    Digits = [0,1,2,3,4,5,6,7,8,9], 
    % select any F
    member(F,Digits), 
    % select any H different from 0
    member(H,Digits), H =\= 0,
    % select any C
    member(C,Digits),
    % select any A different from 0
    member(A,Digits), A =\= 0,    
    % CAFH fixed --> 0-value equation yields E (also verify that E is a Digit)
    E is ( C*A-F-H ), member(E,Digits),           
    % CEAF fixed --> 5-value equation yields I (also verify that I is a nonzero Digit)
    % division by zero in the next equation is verboten
    (E*A-5-F) =\= 0,
    I is (C/(E*A-5-F)), member(I,Digits), I =\= 0,    
    % select any B
    member(B,Digits),    
    % 9-value equation yields D (verify that E is a Digit)
    D is (9-E-A-F+B), member(D,Digits), D =\= 0,
    % 8-value equation yields J (verify that J is a Digit)
    J is (8-E-H+B/D), member(J,Digits), J =\= 0,    
    % 3-value equation yields G (verify that G is a nonzero Digit)
    G is (3+J*I-E*D), member(G,Digits), G =\= 0,    
    % verify remaining constraints
    2 is (D - B / J + I - C),
    1 is (B - J / H - C / A),    
    4 is (A - E + D / G + F),
    6 is (A * C - I + J - G),
    7 is (C / H - J + G * D).
$\endgroup$
  • $\begingroup$ You can certainly optimise the selection of C, since it must be a multiple of H. $\endgroup$ – Peter Taylor Jan 7 '15 at 15:11
0
$\begingroup$

It's totally easy if you think about it.

  • Replace all letters with a digit and solve the equations (letters vs digit).

  • Replace all of the ten distinct letters in the scheme with a single digit (the letters are distinct but not the digit)

  • You must not assign different digits to different letters.

So we must assign one and the same digit to every letter! Just try with 0, 1, 2, 3, and that's it. All letters correspond to the number 3. Even with the most naive approach, we only need to test 10 possible combinations in the worst case, not 10000000000. This puzzle makes programmers angry! :-)

$\endgroup$
0
$\begingroup$

ORACLE 11g Solution

Execute The Following Query:

with x as (select rownum as rnk from dual connect by level<=9),
y as (select x1.rnk a,x2.rnk b,x3.rnk c,x4.rnk d,x5.rnk e,x6.rnk f,x7.rnk g,x8.rnk h,x9.rnk i,x10.rnk j from x x1,x x2,x x3,x x4,x x5,x x6,x x7,x x8,x x9,x x10 )
Select * from y where f+h-ca+e=0
and b-j/h-c/a=1
and d-b/j+i-c=2
and e
d+g-j*i=3
and a-e+d/g+f=4
and f-b+d+e+a=9

$\endgroup$
  • $\begingroup$ Welcome to Puzzling SE! Your answer is pretty incomprehensible, could you please be more clear? If you need help formatting the text, feel free to ask! Also, avoid inserting too much bold content. $\endgroup$ – leoll2 Apr 16 '15 at 12:26
  • $\begingroup$ To programmers and DBA's, it's not incomprehensible... but this isn't the right section of the site for this. $\endgroup$ – generalcrispy Apr 16 '15 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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