Post Reply 
July 2018 little math problem
07-29-2018, 12:10 AM (This post was last modified: 07-29-2018 08:12 PM by Albert Chan.)
Post: #23
RE: July 2018 little math problem
(07-28-2018 04:22 PM)DavidM Wrote:  I'm still trying to wrap my ahead around Albert's and Valentin's approach,
especially in terms of how they might translate to a more familiar language.

This has proven to be an intriguing problem!

Hi, DavidM:

With comments, I can finally understand the code. Thanks.
I do not own any HP calculators (except a hand-me-down HP-12C)

I tried coding in Python, and possibilities is not as high as 252

Brute force all possible values of sum, and it only need 144
Even if sum of 15 is added (why?), it will only reach 180
With complement symmetry, it could be reduced to 72

4 s = 45 + c + e + g
= (45 + 1 + 2 + 3) to (45 + 7 + 8 + 9)
= 51 to 69
= 52, 56, 60, 64, 68

--> s = 13, 14, 15, 16, 17

when s = c + d + e =15, c + e + g = 4 s - 45 = 15, which imply d=g, thus s != 15

Code:
for s in [13, 14, 16, 17]:
    ceg = 4*s - 45
    for c in range(1,9):
        for g in range(c+1, 10):
            e = ceg - c - g
            d = s - e - c
            f = s - e - g
            valid = range(10);              # all single digits
            try: valid[c] = valid[d] = valid[e] = valid[f] = valid[g] = 0
            except IndexError: continue            
            if valid.count(0) != 6: continue

            head = s - c                    # almost done!, now confirm
            valid = filter(None, valid)     # remove the zeroes
            for x in valid:
                if head - x == x: continue
                if head - x in valid: head = [x, head-x]; break
            if type(head) == int: break     # head no good ?
            tail = [x for x in valid if x not in head]
            print head, c, d, e, f, g, tail

And, the expected result ...

[3, 9] 1 8 4 7 2 [5, 6]
[6, 7] 1 5 8 4 2 [3, 9]
[5, 8] 1 6 7 4 3 [2, 9]
[4, 8] 2 9 3 5 6 [1, 7]
[1, 9] 4 8 2 7 5 [3, 6]
[2, 8] 4 9 1 7 6 [3, 5]
[5, 7] 4 3 9 1 6 [2, 8]
[3, 9] 4 5 7 1 8 [2, 6]
[4, 7] 5 3 8 2 6 [1, 9]
[1, 8] 7 6 3 4 9 [2, 5]
[1, 7] 8 6 2 5 9 [3, 4]
[4, 5] 8 3 6 2 9 [1, 7]
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 - 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 - Albert Chan - 07-29-2018 12:10 AM
RE: July 2018 little math problem - pier4r - 08-01-2018, 02:13 PM



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