Project Euler #98: Anagramic squares

  • + 1 comment

    Hints:

    1) For each N, you only need to loop from 10^((N-1)/2) to 10^(N/2). For example: N=4, i runs from 31 to 100. Then take i^2. That saves a lot of time complexity compared with i running from 1000 to 10000 and then taking square root.

    2) A nice trick to store all permutations in any permutation problems: create a dictionary, convert satisfied number as a sorted key. For example: {'1269': [1296, 2916, 9216]}, where '1269' is sorted key of 1296, 2916 and 9216