Skip to content

Instantly share code, notes, and snippets.

@JoelQ
Last active January 12, 2018 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoelQ/6508daab7579ee7fd3099b47ed85df62 to your computer and use it in GitHub Desktop.
Save JoelQ/6508daab7579ee7fd3099b47ed85df62 to your computer and use it in GitHub Desktop.
Attempted solution to the square-sum challenge

Square-Sum Challenge

Write out the numbers 1-15 such that any two numbers in the series add up to a square number

Inspired by https://www.youtube.com/watch?v=G1m7goLCJDY

Possible squares

There are 6 possible squares that can be made by adding two numbers under 16:

  • 1
  • 2
  • 4
  • 9
  • 16
  • 25

Possible combos

Counting down from 15, here are all the possible squares that can be made with each number.

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

Solution

Most numbers can only make two different squares. Thus they have an obvious partner on each side (which side doesn't matter). Counting down from 15, start building chains of numbers between other numbers. When two chains end in the same number, connect them. Eventually you end with a single long chain.

By the time you reach the small numbers that have more than two possible partners, you've already already completed the chain.

Thus the answer is:

9, 7, 2, 14, 11, 5, 4, 12, 13, 3, 6, 10, 15, 1, 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment