All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
A number pyramid (Posted on 2012-05-18) Difficulty: 2 of 5
Divide a set of 10 distinct digits into 4 subsets, each containing a different number of digits, adhering to the following conditions:

Two sets contain digits that can form a reversible prime, in the third set one can create a reversible square number and the remaining set has exactly one member twice as big as another.

Obeying the above restrictions do we get two distinct solutions - as I hope - or more?

See The Solution Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution re(2): computer result: 11 solutions and two almost-solutions Comment 3 of 3 |
(In reply to re: computer result: 11 solutions and two almost-solutions by Ady TZIDON)

The original program did not allow the 3- and 4-digit sets (along with the 2-digit sets, where it legitimately applies) to contain leading zeros, but that, of course, should not have applied to the set that merely accounted for one digit being twice another. That resulted in those solutions not being shown, as the "remainder" set (neither prime nor square) was shown only in it's ascending order, to eliminate trivial permutations, just as the reversible squares and primes were shown only as the lower of the two values.

Only one non-asterisked solution was missed: the one Ady pointed out. One more asterisked pseudo-solution popped up also. I've left them in for the record. It's easier to pick these out by hand than to program them out. Disregard them, and now we have an even dozen legitimate solutions.

The fixed version of the program:

DECLARE SUB permute (a$)
DATA 2,3,5,7,13,17,37,79,107,149,157,167
DATA 179,347,359,389,709,739,769,1069,1097,1237
DATA 1249,1259,1279,1283,1409,1429,1439,1453,1487
DATA 1523,1583,1597,1657,1723,1753,1789,1847,1867
DATA 1879,3019,3049,3067,3089,3109,3169,3257,3407
DATA 3467,3469,3527,3697,3719,3917,7219,7349,7459
DATA 7529,7589,7649

DIM rprime(61)

FOR i = 1 TO 61: READ rprime(i): NEXT
primct = 61

DIM rsquare(6)
WHILE sq < 10000
    sq = n * n
    sqs$ = LTRIM$(STR$(sq))
    revs$ = "": good = 1: REDIM dig(9)
    FOR i = 1 TO LEN(sqs$)
        revs$ = MID$(sqs$, i, 1) + revs$
        d = VAL(MID$(sqs$, i, 1))
        IF dig(d) THEN good = 0
        dig(d) = 1
    NEXT
    r = VAL(revs$)
    sr = INT(SQR(r) + .5)
    IF sr * sr = r AND r >= sq AND good = 1 THEN
        sqct = sqct + 1
        rsquare(sqct) = sq
        PRINT sq;
    END IF
    n = n + 1
WEND
PRINT sqct

digs$ = "0123456789": h$ = digs$

OPEN "rprimesol2.txt" FOR OUTPUT AS #2

DO
    IF MID$(digs$, 2, 1) > "0" THEN
        hadprime = 0: hadsq = 0: haddouble = 0
        a = VAL(MID$(digs$, 1, 1))
        b = VAL(MID$(digs$, 2, 2))
        c = VAL(MID$(digs$, 4, 3))
        d = VAL(MID$(digs$, 7, 4))
        FOR i = 1 TO primct
            IF a = rprime(i) OR b = rprime(i) OR c = rprime(i) AND c > 99 OR d = rprime(i) AND d > 999 THEN
                hadprime = hadprime + 1
                IF a = rprime(i) THEN hp(hadprime) = 1
                IF b = rprime(i) THEN hp(hadprime) = 2
                IF c = rprime(i) AND c > 99 THEN hp(hadprime) = 3
                IF d = rprime(i) AND d > 999 THEN hp(hadprime) = 4
            END IF
        NEXT
        FOR i = 1 TO sqct
            IF a = rsquare(i) OR b = rsquare(i) OR c = rsquare(i) AND c > 99 OR d = rsquare(i) AND d > 999 THEN
                hadsq = hadsq + 1
                IF a = rsquare(i) THEN hs(hadsq) = 1
                IF b = rsquare(i) THEN hs(hadsq) = 2
                IF c = rsquare(i) AND c > 99 THEN hs(hadsq) = 3
                IF d = rsquare(i) AND d > 999 THEN hs(hadsq) = 4
            END IF
        NEXT
        IF hadprime = 2 AND hadsq > 0 THEN
            FOR whsq = 1 TO hadsq
                whchk = 10 - hp(1) - hp(2) - hs(whsq)
                good = 1
                SELECT CASE whchk
                    CASE 1
                        good = 0
                    CASE 2
                        IF VAL(MID$(digs$, 3, 1)) <> 2 * VAL(MID$(digs$, 2, 1)) THEN good = 0
                    CASE 3
                        IF VAL(MID$(digs$, 5, 1)) <> 2 * VAL(MID$(digs$, 4, 1)) AND VAL(MID$(digs$, 6, 1)) <> 2 * VAL(MID$(digs$, 4, 1)) AND VAL(MID$(digs$, 6, 1)) <> 2 * VAL(MID$(digs$, 5, 1)) THEN good = 0
                        IF VAL(MID$(digs$, 5, 1)) < VAL(MID$(digs$, 4, 1)) OR VAL(MID$(digs$, 6, 1)) < VAL(MID$(digs$, 5, 1)) THEN good = 0
                    CASE 4
                        good = 0
                        IF VAL(MID$(digs$, 8, 1)) = 2 * VAL(MID$(digs$, 7, 1)) THEN good = 1
                        IF VAL(MID$(digs$, 9, 1)) = 2 * VAL(MID$(digs$, 7, 1)) THEN good = 1
                        IF VAL(MID$(digs$, 9, 1)) = 2 * VAL(MID$(digs$, 8, 1)) THEN good = 1
                        IF VAL(MID$(digs$, 10, 1)) = 2 * VAL(MID$(digs$, 7, 1)) THEN good = 1
                        IF VAL(MID$(digs$, 10, 1)) = 2 * VAL(MID$(digs$, 8, 1)) THEN good = 1
                        IF VAL(MID$(digs$, 10, 1)) = 2 * VAL(MID$(digs$, 9, 1)) THEN good = 1
                        IF VAL(MID$(digs$, 10, 1)) < VAL(MID$(digs$, 9, 1)) OR VAL(MID$(digs$, 9, 1)) < VAL(MID$(digs$, 8, 1)) OR VAL(MID$(digs$, 8, 1)) < VAL(MID$(digs$, 7, 1)) THEN good = 0
                    CASE ELSE
                        good = 0
                END SELECT
                IF hp(1) = hp(2) THEN good = 0
                IF good THEN
                    ast$ = MID$(digs$, 1, 1)
                    bst$ = MID$(digs$, 2, 2)
                    cst$ = MID$(digs$, 4, 3)
                    dst$ = MID$(digs$, 7, 4)
                    PRINT ast$; " "; bst$; " "; cst$; " "; dst$, hp(1); hp(2), hs(whsq), whchk
                    PRINT #2, ast$; " "; bst$; " "; cst$; " "; dst$, hp(1); hp(2), hs(whsq), whchk
                END IF
            NEXT whsq
        END IF
    END IF
    permute digs$
LOOP UNTIL digs$ = h$
CLOSE 2

SUB permute (a$)
DEFINT A-Z
x$ = ""
FOR i = LEN(a$) TO 1 STEP -1
    l$ = x$
    x$ = MID$(a$, i, 1)
    IF x$ < l$ THEN EXIT FOR
NEXT

IF i = 0 THEN
    FOR j = 1 TO LEN(a$) \ 2
        x$ = MID$(a$, j, 1)
        MID$(a$, j, 1) = MID$(a$, LEN(a$) - j + 1, 1)
        MID$(a$, LEN(a$) - j + 1, 1) = x$
    NEXT
ELSE
    FOR j = LEN(a$) TO i + 1 STEP -1
        IF MID$(a$, j, 1) > x$ THEN EXIT FOR
    NEXT
    MID$(a$, i, 1) = MID$(a$, j, 1)
    MID$(a$, j, 1) = x$
    FOR j = 1 TO (LEN(a$) - i) \ 2
        x$ = MID$(a$, i + j, 1)
        MID$(a$, i + j, 1) = MID$(a$, LEN(a$) - j + 1, 1)
        MID$(a$, LEN(a$) - j + 1, 1) = x$
    NEXT
END IF
END SUB

The new results:

       Sets               sizes of     size of       size of
arranged as numbers        primes      square       remainder
    0 13 246 7589           2  4          1             3 
    0 13 468 7529           2  4          1             3
    0 13 769 2458           2  3          1             4  *
    0 17 359 2468           2  3          1             4  *
    0 17 389 2456           2  3          1             4
    0 24 359 1867           3  4          1             2
    0 24 389 1657           3  4          1             2
    0 24 769 1583           3  4          1             2
    0 37 468 1259           2  4          1             3
    0 48 769 1523           3  4          1             2
    0 79 246 1583           2  4          1             3
    0 79 468 1523           2  4          1             3
    2 37 169 0458           1  2          3             4
    5 37 169 0248           1  2          3             4  *
    5 37 246 1089           1  2          4             3
   
   

  Posted by Charlie on 2012-05-18 18:09:20
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information