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

 Consecutive Trio (Posted on 2014-04-08)
Each of the capital letters in bold represents a different digit from 0 to 9. None of the numbers can contain a leading zero.
1. TWO is a prime number, and:
2. THREE is a triangular number, and:
3. FOUR is a perfect square.
Determine the numbers represented by:
`(i) THREE   (ii) FOUR`
*** *** Adapted from Enigma No. 1341 by Richard England appearing in "New Scientist" on May 21, 2005.

 No Solution Yet Submitted by K Sengupta No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer solution | Comment 2 of 3 |

DECLARE SUB permute (a\$)
CLS

DATA 2,3,5,7,11,13,17,19,23,29,31,37,41
DATA 43,47,53,59,61,67,71,73,79,83,89,97
DATA 101,103,107,109,113,127,131,137,139,149
DATA 151,157,163,167,173,179,181,191,193,197
DATA 199,211,223,227,229,233,239,241,251,257
DATA 263,269,271,277,281,283,293,307,311,313
DATA 317,331,337,347,349,353,359,367,373,379,383
DATA 389,397,401,409,419,421,431,433,439,443,449,457
DATA 461,463,467,479,487,491,499,503,509,521,523
DATA 541,547,557,563,569,571,577,587,593,599,601,607
DATA 613,617,619,631,641,643,647,653,659,661,673,677,683
DATA 691,701,709,719,727,733,739,743,751,757,761,769,773
DATA 787,797,809,811,821,823,827,829,839,853,857,859,863
DATA 877,881,883,887,907,911,919,929,937,941,947,953,967
DATA 971,977,983,991,997,1009

a\$ = "1234567890": h\$ = a\$
DO
IF INSTR(a\$, "0") > 2 THEN
t = VAL(MID\$(a\$, 1, 1))
f = VAL(MID\$(a\$, 2, 1))
w = VAL(MID\$(a\$, 3, 1))
o = VAL(MID\$(a\$, 4, 1))
h = VAL(MID\$(a\$, 5, 1))
r = VAL(MID\$(a\$, 6, 1))
e = VAL(MID\$(a\$, 7, 1))
u = VAL(MID\$(a\$, 8, 1))
two = t * 100 + w * 10 + o
three = 10000 * t + 1000 * h + 100 * r + 11 * e
four = 1000 * f + 100 * o + 10 * u + r
IF INKEY\$ = CHR\$(27) THEN STOP
IF isTri(three) THEN
sr = INT(SQR(four) + .5)
IF sr * sr = four THEN
RESTORE
found = 0
DO
READ pr: IF pr > 999 THEN EXIT DO
IF pr = two THEN found = 1: EXIT DO
LOOP
IF found THEN PRINT two; three; four
END IF
END IF
END IF
permute a\$
LOOP UNTIL a\$ = h\$

SUB permute (a\$)

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

FUNCTION isTri (t)
n = INT(SQR(t * 2))
np = n + 1
IF n * np = 2 * t THEN isTri = n: ELSE isTri = 0
END FUNCTION

finds

137  15400  6724
197  15400  6724

 Posted by Charlie on 2014-04-08 16:37:41

 Search: Search body:
Forums (0)