Solve 6 simultaneous equations for 8 variables puzzle

4.9k Views Asked by At

How to solve this puzzle?

解了一天了 帮帮忙吧


The image was sent to me with a caption in Chinese (解了一天了 帮帮忙吧… - googling leads to some solutions) and blank spaces where I have added letters.

Separating each row and column into individual equations gives the following 6 simultaneous equations:

$a + b - 9 = 4$

$c - de = 4$

$f + g - h = 4$

$a + \frac{c}{f} = 4$

$b - dg = 4$

$9 - e - h = 4$


I believe there must be many, probably infinite solutions, for the above system. But how would one go about mathematically finding one?

If I'm not mistaken, $-\frac{c}{f}-c+de+dg+e-f-g+2h-18=0$ is one general form of the above system. How would I use that to extract real (integer) solutions?

2

There are 2 best solutions below

7
On

I have absolutely no idea how to solve this problem by hand. Here's the code of a Python program to solve the problem:

def calc(a, b, c, d, e, f, g, h):
    '''
    This function checks whether or not all six equations work.
    If one of them fails, it says False.
    If all of them work, it says True.
    '''
    if a+b-9 != 4: return False
    if (c-d)*e != 4: return False
    if f+g-h != 4: return False
    if (a+c)/f != 4: return False
    if (b-d)*g != 4: return False
    if 9-e-h != 4: return False
    return True
# Loop through all possible digits a, b, c, d, e, f, g, h.
for a in range(1, 9):
    for b in range(1, 9):
        for c in range(1, 9):
            for d in range(1, 9):
                for e in range(1, 9):
                    for f in range(1, 9):
                        for g in range(1, 9):
                            for h in range(1, 9):
                                # If the calculation works, then print the digits.
                                if calc(a, b, c, d, e, f, g, h):
                                    print(a, b, c, d, e, f, g, h)

Here is the output of such program:

(5, 8, 7, 6, 4, 3, 2, 1)
(6, 7, 6, 5, 4, 3, 2, 1)
(6, 7, 8, 6, 2, 3, 4, 3)
(7, 6, 5, 4, 4, 3, 2, 1)
(7, 6, 7, 5, 2, 3, 4, 3)
(8, 5, 4, 3, 4, 3, 2, 1)
(8, 5, 6, 4, 2, 3, 4, 3)
(8, 5, 8, 4, 1, 4, 4, 4)

As you can see the first solution is the only solution with unique digits, so I think that is what was intended.

0
On

I assume all the variables are single digits, but do not assume that each digit is represented once in the grid. It is clear that you are not supposed to respect the usual order of operations, because $a$ must be at least $5$, so if you read the first column $a+\frac cf=4$ there is no solution. It must be $\frac{a+c}f=4$

$e$ and $g$ must be $1,2,$ or $4$. If $e=1, h=4, g=2, f=6$ and the first column fails. If $e=2, h=3, $ and $g$ is too large for the first column. If $e=4, h=1, g=2, f=3,$ and $a+b=13, a+c=12$ This means $a \ge 5$. It cannot be $8$ because $c$ would be $4$. It can't be $6$ because $c$ would be as well. $ a=7, c=5, d=4$ gives a solution with two fours. $a=5, c=7, b=8, d=6$ gives a solution with all digits unique.

Generally in problems like this I look for the cells that are most restricted and follow where the possibilities lead.