Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Surjection Strings by Kurush
import itertools
import re
def isometric_strings(str1: str, str2: str) -> bool:
first_set = set(str1)
second_set = set(str2)
if second_set == set():
return True;
for elem in itertools.product(second_set, repeat = len(first_set)):
changes = {}
for char_first_set, char_second_set in zip(first_set, elem):
changes.update({char_first_set: char_second_set})
regex = re.compile("(%s)" % "|".join(map(re.escape, changes.keys())))
str3 = regex.sub(lambda mo: changes[mo.string[mo.start():mo.end()]], str1)
if (str3 == str2): return True
return False
if __name__ == '__main__':
print("Example:")
print(isometric_strings('add', 'egg'))
# These "asserts" are used for self-checking and not for an auto-testing
assert isometric_strings('add', 'egg') == True
assert isometric_strings('foo', 'bar') == False
assert isometric_strings('', '') == True
assert isometric_strings('all', 'all') == True
print("Coding complete? Click 'Check' to earn cool rewards!")
Jan. 20, 2019