# Project Euler #98: Anagramic squares

# Project Euler #98: Anagramic squares

+ 0 comments In python 3, getting a good quick hash for the squares was not obvious at all. I get 90 points in the 2 first tries. Then it took me more than 10 other tries to pass the last test case... But I finally did it :-)

+ 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

+ 2 comments Hint : The problem boils down to writing an acceptable hash method for anagramic strings. The last test case will fail with naive hash methods. Despite the same O(n) complexity for both methods, it makes a huge difference 2+s vs 0.64s.

+ 2 comments I also find the question not-well defined. I suspect the association between words and numbers is misleading (since a list of English words would be required if each number

*really*had to correspond to a word) and instead is introduced as an analogy for the anagram of an arbitrary number (reordering of the decimal digits). Perhaps it is an intentional distraction to obfuscate the question.I could give a precise mathematical description of what I think is required, but (a) that probably wouldn't be in the spirit of the competition, (b) my code doesn't work, so my interpretation is likely to be wrong :-).

+ 0 comments why is test case 0 is failing and rest all are passing? isn't the testcase with N=4? i am able to test my code for N=4 with correct answer of 9216. I am not sure what am i missing.

Sort 18 Discussions, By:

Please Login in order to post a comment