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

 Adjacent Square Sum (Posted on 2013-05-20)
Arrange the numbers 1 to 15 inclusively in a straight line in such a way that any two adjacent numbers add up to a perfect square.

*** Disregard reflections.

 No Solution Yet Submitted by K Sengupta No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 re: P 'n P and then ... -- recursive method added Comment 3 of 3 |
(In reply to P 'n P and then ... by brianjn)

CLEAR , , 25000
PRINT
DIM SHARED h(15), used(15)

FOR first = 1 TO 14
h(1) = first
used(first) = 1
used(first) = 0
NEXT

FOR new = 1 TO 15
IF used(new) = 0 THEN
pair = h(n - 1) + new
sr = INT(SQR(pair) + .5)
IF sr * sr = pair THEN
h(n) = new
used(new) = 1

IF n = 15 THEN
IF h(15) > h(1) THEN
FOR i = 1 TO 15
PRINT USING "###"; h(i);
NEXT: PRINT
PRINT "  ";
FOR i = 1 TO 14
PRINT USING "###"; h(i) + h(i + 1);
NEXT: PRINT
END IF
ELSE
END IF

used(new) = 0
END IF
END IF
NEXT
END SUB

This also prevents reflections by requiring the last number to be higher than the first in the list in order to be printed out.

The results show the sequence as well as the pattern in the sums of pairs:

`8  1 15 10  6  3 13 12  4  5 11 14  2  7  9  9 16 25 16  9 16 25 16  9 16 25 16  9 16`

 Posted by Charlie on 2013-05-21 09:54:58

 Search: Search body:
Forums (0)