StandupMaths Puzzle: Is 36 the only triangle-square number?

This is a solution response to standupmaths video https://www.youtube.com/watch?v=Gh8h8MJFFdI

Objective was to find triangle-square whole numbers, where:

N2 = M * (M + 1) / 2

And also - try to spot a pattern by which these numbers occure.

Part 1: Find the numbers

First i tried with a brute force javascript, so i wrote next couple of lines into my chrome console to scan through first 1'000'000'000 numbers for solutions:

(function () {
  var n, m, s = 0, l = 1000000000, i = 0, t = new Date();
  console.log("#,   N,   M,   Math.pow(N, 2),   M * (M + 1) / 2");
  for (m = s; m <= l; m++) {
    n = Math.sqrt(m * (m + 1) / 2);
    if (Math.round(n) === n) {
      console.log(++i + ".", n, m, Math.pow(n, 2), (m * (m + 1) / 2));
    }
  }
  return "Found " + i + " solutions for '" + s + " <= m <= " + l + "' in " + ((new Date() - t) / 1000).toFixed(3) + " seconds";
})();

Results:

Part 2: Find the pattern

Next i started to look for pattern, but soon i realized that my javascript code fails just as soon it hits 16+ digit numbers and thats because of browsers inability to handle big integers.
For example Math.sqrt(7263325169820735) and Math.sqrt(7263325169820736) produce the same result: 85225144 and because of it i got massive amount of false positives and i had to drop all large number results.

Altough javascript failed to give me reliable results on large numbers, it did give me correct results on about dozen of first calculations. This was enough for starting to look if i could spot any patterns.

It took me couple of hours or so, but i did find one odd pattern - i can calculate any new number N based on previous 5 numbers. And formula i came up with, looks like this:

((n1 + n5) / n3 * n4) - n2

Since i already have five numbers from the sequence 0, 1, 6, 35, 204, it's easy to find next one: ((0 + 204) / 6 * 35) - 1 = 1189

And now for the M, since N2 = M * (M + 1) / 2 then M must be:

N2 = M(M + 1) / 2
M(M + 1) = 2N2
M = -1/2 + squareroot((1/2)2 + 2N2)
M = -0.5 + squareroot(0.25 + 2N2)
M = squareroot(2N2 + 0.25) - 0.5

    therefore

M = squareroot(2 * 11892 + 0.25) - 0.5 = 1681

Now just write a loop to generate more numbers:

(function () {
  var
    n1 = 0,
    n2 = 1,
    n3 = 6,
    n4 = 35,
    n5 = 204,
    i = 0,
    l = 50,
    t = new Date();

  console.log("#,   N,   M,   Math.pow(N, 2),   M * (M + 1) / 2");
  console.log(++i + ".", 0, 0, 0, 0);
  console.log(++i + ".", 1, 1, 1, 1);
  console.log(++i + ".", 6, 8, 36, 36);
  console.log(++i + ".", 35, 49, 1225, 1225);
  console.log(++i + ".", 204, 288, 41616, 41616);

  while (i < l) {
    n = ((n1 + n5) / n3 * n4) - n2;
    m = Math.sqrt((2 * Math.pow(n, 2)) + 0.25) - 0.5;

    console.log(++i + ".", n, m, Math.pow(n, 2), (m * (m + 1) / 2));

    n1 = n2;
    n2 = n3;
    n3 = n4;
    n4 = n5;
    n5 = n;
  }

  return "Found " + i + " solutions in " + ((new Date() - t) / 1000).toFixed(3) + " seconds";
})();

And the result:

Since applying this pattern returns same results for the first dozen of numbers as the first code snippet, i can only assume it works :)
To actually verify it i'm gonna need much more computation power...

jevgeni virves