

The following problem appeared as ENIGMA 1162 in New Scientist 24 November 2001
TRIANGULAR OR SQUARERichard EnglandHARRY and Tom each chose a fourdigit number that was either a perfect square or a triangle number and told me its last two digits. I deduced that Harry's number was one of exactly two fourdigit perfect squares or one of exactly two fourdigit triangular numbers, but that Tom's number was one of exactly three fourdigit perfect squares or one of exactly three fourdigit triangular numbers. Then they told me that the sum of the digits of Harry's number was the same as the sum of of the digits of Tom's number. What were (a) Harry's number and (b) Tom's number? 
We need fewer than 144 numbers to generate all four digit squares and triangle. The following code generates the numbers 0, 1, 2 .. 143 as attribute i in table t_num.
1  Check that the tables primes exists by viewing all primes less than 50. 
