Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
11-liner: Function Recursion solution in Speedy category for String Conversion by Stensen
from functools import lru_cache
@lru_cache(maxsize=None)
def steps_to_convert(line1, line2):
if line1 == line2 == '': return 0
if not line1: return len(line2)
if not line2: return len(line1)
if line1[0] == line2[0]: return steps_to_convert(line1[1:], line2[1:])
remove = steps_to_convert(line1[1:], line2)
prepend = steps_to_convert(line2[0] + line1, line2)
replace = steps_to_convert(line2[0] + line1[1:], line2)
return min(remove, prepend, replace) + 1
Oct. 9, 2020