How many square numbers use all the digits 0 to 9 once and once only?
If you think you've solved it, or if you're stuck, email firstname.lastname@example.org or tweet to @pi3challenge
A square number
is one that can be written as the square of another number. For example, 9 is a square number, because 9 = 32
= 3 x 3.
An example of a number with all the digits once only is 9586714230. But this is not a square number. An example of a number with all the digits once only which is also
a square number is 1532487609 = 391472
: Whereas Challenge #1
needed some subtle mathematical reasoning, this challenge just needs your programming skills. Hint #2
functions are very useful for this problem. Take a look at this page on lists, strings and sets
. Find out how a number can be turned into a string which can then be turned into a list or set. Extra challenges:
- How many prime numbers can be written as N+1, where N is a square number with all digits.
- How many prime numbers can be written as N-1, where N is a square number with all digits. Is this just coincidence, or can you find an explanation?
- How many of the roots n of these square numbers, n^2 = N, are themselves prime numbers? Coincidence, or can you find an explanation?
- How many permutations of the digits 9876543210 are there? How many of these are valid numbers? What proportion of such numbers are square numbers?
- Can you find an example of a number whose square contains each digit exactly twice?