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

Home > Just Math
Adjacent Square Sum (Posted on 2013-05-20) Difficulty: 2 of 5
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.)
Solution re: P 'n P and then ... -- recursive method added | Comment 3 of 5 |
(In reply to P 'n P and then ... by brianjn)

DECLARE SUB addOn (n!)
CLEAR , , 25000
PRINT
DIM SHARED h(15), used(15)

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

SUB addOn (n)
  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
           addOn n + 1
        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
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


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

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