Created
July 31, 2021 13:02
-
-
Save igorvanloo/8b8d6a42df1e20438253c276a05fc15c to your computer and use it in GitHub Desktop.
Problem 98
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wordchecker(word, number): | |
word_fingerprint = [] | |
for x in word: | |
word_fingerprint.append(word.count(x)) | |
number_fingerprint = [] | |
for x in number: | |
number_fingerprint.append(number.count(x)) | |
if word_fingerprint == number_fingerprint: | |
return True | |
return False | |
def compute(): | |
candidates = [] | |
for x in range(len(words)): | |
for y in range(x+1, len(words)): | |
if sorted(list(words[x])) == sorted(list(words[y])): | |
candidates.append((len(words[x]), (words[x], words[y]))) | |
candidates = sorted(candidates)[::-1] | |
possiblesquares = [str(x**2) for x in range(1,31623)] | |
for x in candidates: | |
for y in possiblesquares: | |
length = len(y) | |
if length > x[0]: | |
break | |
if length == x[0]: | |
word = x[1][0] | |
if wordchecker(word, y): | |
temp_dict = {} | |
for z in range(len(word)): | |
if word[z] not in temp_dict: | |
temp_dict[word[z]] = y[z] | |
number = "" | |
for a in x[1][1]: | |
number += temp_dict[a] | |
if number in possiblesquares: | |
return max(int(y), int(number)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment