Post Reply 
July 2018 little math problem
07-26-2018, 03:43 PM
Post: #12
RE: July 2018 little math problem
(07-26-2018 12:36 PM)pier4r Wrote:  I do believe there is a strong pattern. Mine is pretty weak but I didn't yet see it, maybe because I did not strictly check the posted code.

We can start with \(e\in\{1\ldots9\}\). And then let \(c\) and \(g\) be different digits with \(c<g\). This gives us \(9\times\binom{8}{2}=252\) possibilities.

But since \(s=a+b+c=c+d+e=e+f+g=g+h+i\) and \(a+b+c+d+e+f+g+h+i=\sum_{k=1}^{9}k=45\) we know that their sum is \(4s=45+c+e+g\) which must be divisible by 4.
This reduces the possibilities further down to 60.

We can now calculate \(d=s-c-e\) and \(f=s-e-g\) and check that both are digits.
And of course each element of \(\{c,d,e,f,g\}\) must be unique.

With this we're down at 12 possibilities:
Code:
Spoiler alert!










c d e f g | s
----------+---
4 9 1 7 6 | 14
4 8 2 7 5 | 14
8 6 2 5 9 | 16
2 9 3 5 6 | 14
7 6 3 4 9 | 16
1 8 4 7 2 | 13
8 3 6 2 9 | 17
1 6 7 4 3 | 14
4 5 7 1 8 | 16
1 5 8 4 2 | 14
5 3 8 2 6 | 16
4 3 9 1 6 | 16

Now it's easy to find \(a\) and \(b\) so that \(a+b+c=s\) and similarly find \(h\) and \(i\) so that \(g+h+i=s\).

Code:
Spoiler alert!










from itertools import combinations

digits = set(range(1, 10))

for e in digits:
    E = digits.copy()
    E.remove(e)
    for c, g in combinations(E, 2):
        t = 45 + c + e + g
        if t % 4:
            continue
        s = t / 4
        d = s - c - e
        if d not in digits:
            continue
        f = s - e - g
        if f not in digits:
            continue
        used = set([c, d, e, f, g])
        if len(used) != 5:
            continue
        rest = digits - used
        for a, b in combinations(rest, 2):
            if a+b+c != s:
                continue
            h, i = rest - set([a, b])
            if g+h+i != s:
                continue
            print a, b, c, d, e, f, g, h, i

Checking only 252 instead of 9! = 362,880 possibilities speeds us up by the factor 1,440.
Even checking that 45+c+e+g is divisible by 4 is rather simple.

Thus here's a program for the HP-42S that lists possible tuples "c:d:e:f:g".
You have to weed some of them out though.
But that's still easier than doing the whole calculation manually.

Code:
Spoiler alert!










9
STO 00
LBL 00
9
STO 01
LBL 01
9
STO 02
LBL 02
RCL 01
RCL 02
X≤Y?
GTO 09
+
RCL+ 00
45
+
4
÷
RCL- 00
ENTER
IP
X≠Y?
GTO 09
RCL-02
X<>Y
RCL- 01
CLA
ARCL 01
 ⊦":"
ARCL ST X
 ⊦":"
ARCL 00
 ⊦":"
ARCL ST Y
 ⊦":"
ARCL 02
AVIEW
LBL 09
DSE 02
GTO 02
DSE 01
GTO 01
DSE 00
GTO 00

Make sure to have the display mode set to ALL.

This will lead to a list like this:

6:2:9:0:8 → discard since f=0 is not valid
5:3:9:-1:9 → discard since f=-1 is not valid
4:3:9:1:6 → this is a valid solution
...


Cheers
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
July 2018 little math problem - pier4r - 07-25-2018, 08:52 PM
RE: July 2018 little math problem - DavidM - 07-26-2018, 04:03 AM
RE: July 2018 little math problem - DavidM - 07-26-2018, 03:38 PM
RE: July 2018 little math problem - pier4r - 07-26-2018, 12:36 PM
RE: July 2018 little math problem - Thomas Klemm - 07-26-2018 03:43 PM
RE: July 2018 little math problem - pier4r - 07-27-2018, 10:03 AM
RE: July 2018 little math problem - DavidM - 07-28-2018, 04:22 PM
RE: July 2018 little math problem - pier4r - 08-01-2018, 02:13 PM



User(s) browsing this thread: 1 Guest(s)