Algebra problem stumping me

267 Views Asked by At

I have recently run into an algebra problem that goes as follows.

Using the digits $1$ to $9$, $$ \left\{ \begin{align} A + B + C + D &= EF \\ E + F + G + H &= CJ \\ B + G + J &= ?D \\ \text{total} &= B? \end{align} \right. $$

also $A-H > F$ where each letter is a different unique number.

I believe when it says $EF$ it does not mean $E \cdot F$, but more like if answer was $15$, $E = 1$ and $F = 5$ sort of thing.

Been working on this for hours, even attempted to write a computer program to help solve but to no avail.

Any tips on how to solve (or a work through of it) would be greatly appreciated.

6

There are 6 best solutions below

2
On BEST ANSWER

$$ \left\{ \begin{align} A + B + C + D &= EF \\ E + F + G + H &= CJ \\ B + G + J &= xD \\ EF + CJ + xD &= By \\ A - H &\gt F \end{align} \right. $$

$\begin{align} \\ A &\in \{1,2,3,4,5,6,7,8,9\} \\ B &\in \{1,2,3,4,5,6,7,8,9\} \\ C &\in \{1,2,3,4,5,6,7,8,9\} \\ D &\in \{1,2,3,4,5,6,7,8,9\} \\ E &\in \{1,2,3,4,5,6,7,8,9\} \\ F &\in \{1,2,3,4,5,6,7,8,9\} \\ G &\in \{1,2,3,4,5,6,7,8,9\} \\ H &\in \{1,2,3,4,5,6,7,8,9\} \\ J &\in \{1,2,3,4,5,6,7,8,9\} \\ x &\in \{1,2,3,4,5,6,7,8,9\} \\ y &\in \{1,2,3,4,5,6,7,8,9\} \\ \end{align}$


$$A + B + C + D \le 6+ 7 + 8 + 9 = 30 \\ F \ne 0 \\ \begin{align} &\implies EF \le 29, CJ \le 29 \\ &\implies E,C \in \{1,2\} \end{align}$$


$$B + G + J \le 7 + 8 + 9 = 24 \\ xD \le 24 \implies x \in \{1,2\}$$


$$F + J + D \le 7 + 8 + 9 = 24 \implies \text{carry} \le 2 \\ 4 = 1 + 2 + 1 + 0 \le E + C + x + \text{carry} \le 1 + 2 + 2 + 2 = 7 \\ \implies B \in \{4,5,6,7\}$$

$\begin{align} \\ C &\in \{1,2\} \\ E &\in \{1,2\} \\ B &\in \{4,5,6,7\} \\ A &\in \{3,4,5,6,7,8,9\} \\ D &\in \{3,4,5,6,7,8,9\} \\ F &\in \{3,4,5,6,7,8,9\} \\ G &\in \{3,4,5,6,7,8,9\} \\ H &\in \{3,4,5,6,7,8,9\} \\ J &\in \{3,4,5,6,7,8,9\} \\ x &\in \{1,2\} \\ y &\in \{1,2,3,4,5,6,7,8,9\} \\ \end{align}$


$$A > F + H \ge 3 + 4 = 7 \implies A \in \{8,9\} \\ 9 = 3 + 6 > F + H \ge 3 + 4 \implies F,H \in \{3,4,5\} \\ F + H \in \left\{ \begin{align} 3+4=7 \\ 3+5=8 \end{align} \right. \\ 3 \in \{F,H\}$$

$\begin{align} \\ C &\in \{1,2\} \\ E &\in \{1,2\} \\ F &\in \{3,4,5\} \\ H &\in \{3,4,5\} \\ B &\in \{4,5,6,7\} \\ D &\in \{4,5,6,7,8,9\} \\ G &\in \{4,5,6,7,8,9\} \\ J &\in \{4,5,6,7,8,9\} \\ A &\in \{8,9\} \\ x &\in \{1,2\} \\ y &\in \{1,2,3,4,5,6,7,8,9\} \\ \end{align}$


$$EF \in \{ 13, 14, 15, 23, 24, 25 \} \\ EF = A + B + C + D \ge 8 + 4 + 1 + 4 = 17 \\ \implies E=2 \implies C=1$$

$\begin{align} \\ C &\in \{1\} \\ E &\in \{2\} \\ F &\in \{3,4,5\} \\ H &\in \{3,4,5\} \\ B &\in \{4,5,6,7\} \\ D &\in \{4,5,6,7,8,9\} \\ G &\in \{4,5,6,7,8,9\} \\ J &\in \{4,5,6,7,8,9\} \\ A &\in \{8,9\} \\ x &\in \{1,2\} \\ y &\in \{1,2,3,4,5,6,7,8,9\} \\ \end{align}$


$$E + F + G + H = CJ \implies F + H + G = 8 + J \\ F + H \in \{7,8\} \\ F + H = 8 \implies G = J \text{ (contradiction)} \\ \implies F + H = 7 = 3 + 4 \implies 5 \notin \{F,H\} \\ \implies \{F,H\} = \{3,4\}$$


$$\implies G = 1 + J \qquad (*)$$

$\begin{align} \\ C &\in \{1\} \\ E &\in \{2\} \\ F &\in \{3,4\} \\ H &\in \{3,4\} \\ B &\in \{5,6,7\} \\ J &\in \{5,6,7,8\} \\ G &\in \{6,7,8,9\} \\ D &\in \{5,6,7,8,9\} \\ A &\in \{8,9\} \\ x &\in \{1,2\} \\ y &\in \{1,2,3,4,5,6,7,8,9\} \\ \end{align}$


$$\begin{align} J + G + B &= xD \\ 5 + 6 + 7 &= 18 \\ 6 + 7 + 5 &= 18 \\ 7 + 8 + 5 &= 20 \, \, (D \ne 0) \\ 7 + 8 + 6 &= 21 \, \, (D \ne 1) \\ 8 + 9 + 5 &= 22 \, \, (D \ne 2) \\ 8 + 9 + 6 &= 23 \, \, (D \ne 3) \\ 8 + 9 + 7 &= 24 \, \, (D \ne 4) \end{align}$$

$$\implies D=8 \implies A=9$$

$\begin{align} \\ C &\in \{1\} \\ E &\in \{2\} \\ F &\in \{3,4\} \\ H &\in \{3,4\} \\ B &\in \{5,7\} \\ J &\in \{5,6\} \\ G &\in \{6,7\} \\ D &\in \{8\} \\ A &\in \{9\} \\ x &\in \{1\} \\ y &\in \{1,2,3,4,5,6,7,8,9\} \\ \end{align}$


$$A + B + C + D = EF \implies B + 18 = F + 20 \implies B = F + 2 \\ \implies F = 3, \, B = 5 \\ \implies H = 4, \, J = 6, \, G = 7 \\ \implies y = 7$$

$\begin{align} \\ C &\in \{1\} \\ E &\in \{2\} \\ F &\in \{3\} \\ H &\in \{4\} \\ B &\in \{5\} \\ J &\in \{6\} \\ G &\in \{7\} \\ D &\in \{8\} \\ A &\in \{9\} \\ x &\in \{1\} \\ y &\in \{7\} \\ \end{align}$

12
On

There's something missing to the problem, or we've made an invalid assumption.

Assumptions:

  • "$EF$" means $10\cdot E+F$
  • $total$ means $A+B+\dots +J$ and it equals $45$
    • Which means $B=4$


Using Mathematica:
Input:

Reduce[a+b+c+d==e*10+f
    && e+f+g+h==c*10+j
    && b+g+j ==x*10+d
    && b==4
    && a-h>f
    && (a|c|d|e|f|g|h|j|x) \[Element] Integers
    && 1<=a<=9
    && 1<=c<=9
    && 1<=d<=9
    && 1<=e<=9
    && 1<=f<=9
    && 1<=g<=9
    && 1<=h<=9
    && 1<=j<=9
    && 1<=x<=9]

Output:

((a==3 && c==1 && d==3 && e==1 && f==1 && g==8 && h==1 && j==1 && x==1)||
 (a==4 && c==1 && d==2 && e==1 && f==1 && g==7 && h==2 && j==1 && x==1)||
 (a==5 && c==1 && d==1 && e==1 && f==1 && g==6 && h==3 && j==1 && x==1)||
 (a==5 && c==1 && d==2 && e==1 && f==2 && g==7 && h==1 && j==1 && x==1)||
 (a==5 && c==1 && d==3 && e==1 && f==3 && g==7 && h==1 && j==2 && x==1)||
 (a==6 && c==1 && d==1 && e==1 && f==2 && g==6 && h==2 && j==1 && x==1)||
 (a==6 && c==1 && d==2 && e==1 && f==3 && g==6 && h==2 && j==2 && x==1)||
 (a==7 && c==1 && d==1 && e==1 && f==3 && g==5 && h==3 && j==2 && x==1)||
 (a==7 && c==1 && d==1 && e==1 && f==3 && g==6 && h==1 && j==1 && x==1)||
 (a==7 && c==1 && d==2 && e==1 && f==4 && g==6 && h==1 && j==2 && x==1)||
 (a==7 && c==1 && d==3 && e==1 && f==5 && g==6 && h==1 && j==3 && x==1)||
 (a==7 && c==1 && d==9 && e==2 && f==1 && g==9 && h==4 && j==6 && x==1)||
 (a==8 && c==1 && d==1 && e==1 && f==4 && g==5 && h==2 && j==2 && x==1)||
 (a==8 && c==1 && d==2 && e==1 && f==5 && g==5 && h==2 && j==3 && x==1)||
 (a==8 && c==1 && d==8 && e==2 && f==1 && g==8 && h==5 && j==6 && x==1)||
 (a==8 && c==1 && d==8 && e==2 && f==1 && g==9 && h==3 && j==5 && x==1)||
 (a==8 && c==1 && d==9 && e==2 && f==2 && g==8 && h==5 && j==7 && x==1)||
 (a==8 && c==1 && d==9 && e==2 && f==2 && g==9 && h==3 && j==6 && x==1)||
 (a==9 && c==1 && d==1 && e==1 && f==5 && g==4 && h==3 && j==3 && x==1)||
 (a==9 && c==1 && d==1 && e==1 && f==5 && g==5 && h==1 && j==2 && x==1)||
 (a==9 && c==1 && d==1 && e==1 && f==5 && g==9 && h==3 && j==8 && x==2)||
 (a==9 && c==1 && d==2 && e==1 && f==6 && g==5 && h==1 && j==3 && x==1)||
 (a==9 && c==1 && d==3 && e==1 && f==7 && g==5 && h==1 && j==4 && x==1)||
 (a==9 && c==1 && d==7 && e==2 && f==1 && g==7 && h==6 && j==6 && x==1)||
 (a==9 && c==1 && d==7 && e==2 && f==1 && g==8 && h==4 && j==5 && x==1)||
 (a==9 && c==1 && d==7 && e==2 && f==1 && g==9 && h==2 && j==4 && x==1)||
 (a==9 && c==1 && d==8 && e==2 && f==2 && g==7 && h==6 && j==7 && x==1)||
 (a==9 && c==1 && d==8 && e==2 && f==2 && g==8 && h==4 && j==6 && x==1)||
 (a==9 && c==1 && d==8 && e==2 && f==2 && g==9 && h==2 && j==5 && x==1)||
 (a==9 && c==1 && d==9 && e==2 && f==3 && g==8 && h==4 && j==7 && x==1)||
 (a==9 && c==1 && d==9 && e==2 && f==3 && g==9 && h==2 && j==6 && x==1))
&& b==-a-c-d+10 e+f
2
On

Since you mentioned using a program, and the generalization of this problem is NP-complete anyway, here is the solution:

A:9 B:5 C:1 D:8 E:2 F:3 G:7 H:4 I:6 x:1 y:7

The "main part" of the code:

int main() {

  int digits = 9;
  int digit_array[digits];

  for (permutation_initialize(digit_array, digits, 1);
       permutation_finished  (digit_array, digits, 1);
       permutation_next      (digit_array, digits, 1)) {

    int a = digit_array[0];
    int b = digit_array[1];
    int c = digit_array[2];
    int d = digit_array[3];
    int e = digit_array[4];
    int f = digit_array[5];
    int g = digit_array[6];
    int h = digit_array[7];
    int j = digit_array[8];

    int sum1 = a + b + c + d;
    int sum2 = e + f + g + h;
    int sum3 = b + g + j;

    if (sum1 != 10*e + f) continue;
    if (sum2 != 10*c + j) continue;
    if (a - h <= f) continue;

    for (int x = 1; x <= 9; x++) {

      if (sum3 != 10*x + d) continue;
      if (((sum1 + sum2 + sum3) / 10) != b) continue;
      print_array(digit_array, digits);
      printf("x:%d y:%d\n", x, (sum1 + sum2 + sum3)%10);
   }
 }
 return 0;
}

I realize this is only comment worthy but it's too long, and hopefully it will help motivate due to the demonstration that there is a unique answer.

3
On

Assumptions:

  • "$EF$" means $10\cdot E+F$
  • $total$ means $EF+CJ+xD+By$


Using Mathematica:
Input:

Reduce[a+b+c+d==e*10+f
    && e+f+g+h==c*10+j
    && b+g+j ==x*10+d
    && 10*(e+c+x)+(f+j+d)==b*10+y
    && a-h>f
    && (a|b|c|d|e|f|g|h|j|x|y) \[Element] Integers
    && 1<=a<=9
    && 1<=b<=9
    && 1<=c<=9
    && 1<=d<=9
    && 1<=e<=9
    && 1<=f<=9
    && 1<=g<=9
    && 1<=h<=9
    && 1<=j<=9
    && 1<=x<=9
    && 1<=y<=9]

The output was 45 different possibilities. Filtering for uniqueness left 1 solution:

(a==9 && b==5 && c==1 && d==8 && e==2 && f==3 && g==7 && h==4 && j==6 && x==1 && y==7)

Now that we know the right assumptions that lead to a unique solution ... who can show him how to solve it by hand?

3
On

There are a number of ways to approach this. In the following I assume: A,B,C,D,E,F,G,H,J are distinct from 1 to 9 and total refers to the sum of the previous equations.

The following Mathematica code firstly reduces the candidate partitions of Range[9] to achieve first two criteria then searches this reduced space for solutions.This is a little faster than looking through 362880 permutations.

ran = Range[9];
sub = Subsets[ran, {4}];
cand = Select[
   Select[Select[
     Select[Flatten[
       Map[Function[
         x, {#, x, Total@#, Total@x, Intersection[#, x]} & /@ sub], 
        sub], 1], Last@# == {} &], 
     Not[Or[IntegerDigits[#[[3]]][[2]] == 0, 
        IntegerDigits[#[[4]]][[2]] == 0]] &], 
    Length@Intersection[#[[2]], IntegerDigits[#[[3]]]] == 2 &],
   And[
     MemberQ[#[[1]], IntegerDigits[#[[4]]][[1]]], 
     Not[MemberQ[#[[1]], IntegerDigits[#[[4]]][[2]]]], 
     Not[MemberQ[#[[2]], IntegerDigits[#[[4]]][[2]]]]] &
   ];
fun[u_, v_, w_] := 
 Module[{pu, pv, a, b, c, d, e, f, g, h, j, r1, r2, r3, tp},
  pu = Permutations[u];
  pv = Permutations[v];
  r1 = Thread[{a, b, c, d} -> #] & /@ pu;
  r2 = Thread[{e, f, g, h} -> #] & /@ pv;
  r3 = {j -> IntegerDigits[w][[2]]};
  tp = Partition[Flatten[Tuples[{r1, r2, r3}]], 9];
  #[[All, 2]] & /@ 
   Union[Select[tp, 
     And[a + b + c + d == 10 e + f, e + f + g + h == 10 c + j, 
        b + g + j > 10, Mod[b + g + j, 10] == d, 
        IntegerPart[(a + b + c + d + e + f + g + h + b + g + j)/10] == 
         b] /. # &]]
  ]
arg = cand[[All, {1, 2, 4}]];
answers = Cases[fun @@ # & /@ arg, Except[{}]];
dat[x_] := 
 Join[x, {Total[x[[1 ;; 4]]], Total[x[[5 ;; 8]]], 
   x[[2]] + x[[7]] + x[[9]], 
   Total[{Total[x[[1 ;; 4]]], Total[x[[5 ;; 8]]], 
     x[[2]] + x[[7]] + x[[9]]}]}]
tab = Column[
  TableForm[#, 
     TableHeadings -> {None, {"a", "b", "c", "d", "e", "f", "g", "h", 
        "j", "c1", "c2", "c3", "c4"}}] & /@ Map[dat, answers, {2}]]

I apologize for the ugliness of the code. It yields the following (where c1,c2,c3,c4 are the constraints of the puzzle, e.g. c1= A+B+C+D=EF} enter image description here

Update

In light of the additional constraint mentioned in comment:

  1. cand selects two disjoint subsets of {1,2,3,...,9}of size 4 with the properties that the first subset sums to a two digit number whose digits are in the second subset and the sum of the digits in this second subset has first digit in first subset.
  2. fun then evaluates candidate partitions and selects the order that satisfies the constraints. This is applied to relevant elements of cand
  3. dat is just a way to display solution and tab displays it.

In light of constraint A-H>F here is the trivially modified code:

ran = Range[9];
sub = Subsets[ran, {4}];
cand = Select[
   Select[Select[
     Select[Flatten[
       Map[Function[
         x, {#, x, Total@#, Total@x, Intersection[#, x]} & /@ sub], 
        sub], 1], Last@# == {} &], 
     Not[Or[IntegerDigits[#[[3]]][[2]] == 0, 
        IntegerDigits[#[[4]]][[2]] == 0]] &], 
    Length@Intersection[#[[2]], IntegerDigits[#[[3]]]] == 2 &],
   And[
     MemberQ[#[[1]], IntegerDigits[#[[4]]][[1]]], 
     Not[MemberQ[#[[1]], IntegerDigits[#[[4]]][[2]]]], 
     Not[MemberQ[#[[2]], IntegerDigits[#[[4]]][[2]]]]] &
   ];
fun[u_, v_, w_] := 
 Module[{pu, pv, a, b, c, d, e, f, g, h, j, r1, r2, r3, tp},
  pu = Permutations[u];
  pv = Permutations[v];
  r1 = Thread[{a, b, c, d} -> #] & /@ pu;
  r2 = Thread[{e, f, g, h} -> #] & /@ pv;
  r3 = {j -> IntegerDigits[w][[2]]};
  tp = Partition[Flatten[Tuples[{r1, r2, r3}]], 9];
  #[[All, 2]] & /@ 
   Union[Select[tp, 
     And[a + b + c + d == 10 e + f, e + f + g + h == 10 c + j, 
        b + g + j > 10, Mod[b + g + j, 10] == d, 
        IntegerPart[(a + b + c + d + e + f + g + h + b + g + j)/10] == 
         b, a - h > f] /. # &]]
  ]
arg = cand[[All, {1, 2, 4}]];
answers = Cases[fun @@ # & /@ arg, Except[{}]];
dat[x_] := 
 Join[x, {Total[x[[1 ;; 4]]], Total[x[[5 ;; 8]]], 
   x[[2]] + x[[7]] + x[[9]], 
   Total[{Total[x[[1 ;; 4]]], Total[x[[5 ;; 8]]], 
     x[[2]] + x[[7]] + x[[9]]}]}]
tab = Column[
  TableForm[#, 
     TableHeadings -> {None, {"a", "b", "c", "d", "e", "f", "g", "h", 
        "j", "c1", "c2", "c3", "c4"}}] & /@ Map[dat, answers, {2}]]

yielding the unique solution:

enter image description here

1
On

Solutions of this problem can be easily obtained in Mathematica.

It turns out that there is just one solution, as it should be for this type of puzzle.

The equations are

eq1 = a + b + c + d == 10 e + f;
eq2 = e + f + g + h == 10 c + j;
eq3 = b + g + j == 10 x + d;
eq4 = 10 e + f + 10 c + j + 10 x + d == 10 b + y;
eq5 = a - h == f + z;

Here we have modified the inequality to an equation eq5. Notice that the auxiliary quantities x, y, and z are also decimal digits, but they are allowed to be equal to one of the main variables.

The condition of all variables being a decimal place is

dec = And @@ Thread[1 <= {a, b, c, d, e, f, g, h, j, x, y, z} <= 9];

The solution is obtained in a matter of seconds:

sol = Solve[Reduce[eq1 && eq2 && eq3 && eq4 && eq5 && dec, Integers]];
Length[sol]

(* Out[192]= 45 *)

Now we impose on these 45 tuples the condition that all main variables {a, ...,j} are pairwise different.

sel = Select[{a, b, c, d, e, f, g, h, j, x, y, z} /. sol, 
  Length[Union[Take[#, {1, 9}]]] == 9 &]

(* Out[187]= {{9, 5, 1, 8, 2, 3, 7, 4, 6, 1, 7, 2}} *)

This is the unique solution.

Writen in replacement format it becomes:

List @@ Inner[Rule, {a, b, c, d, e, f, g, h, j, x, y, z}, sel[[1]]]

(*
Out[188]= {a -> 9, b -> 5, c -> 1, d -> 8, e -> 2, f -> 3, g -> 7, h -> 4, j -> 6,  x -> 1, y -> 7, z -> 2}
*)

Observation

There are two obvious points in the code which can certainly be improved

1) the selection should be done immediately in the conditions to be fed into Reduce[]

2) The replacement form should have a more elegant form