Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Regex solves charades solution in Clear category for Tricky String by Kolia951
import re
def tricky_string(text: str) -> str:
# masks for every symbol in the "CheckIO"
masks = [
"[Cc].{6}", ".{1}[Hh].{5}", ".{2}[Ee].{4}", ".{3}[Cc].{3}",
".{4}[Kk].{2}", ".{5}[Ii].{1}", ".{6}[Oo]"
]
matchings = []
# apply masks and check the difference
for item in masks:
res = re.findall(item, text)
# verify every found substring against "CheckIO"
for substring in res:
gaps = zip("CheckIO", substring)
# count number of different symbols
gaps_count = sum([1 for i,j in gaps if i != j])
# add all of them into the list
elem = (gaps_count, text.find(substring))
matchings.append(elem)
# find an element with the min differense with "CheckIO"
position = min(matchings)[1]
# create a final string
final_result = text[:position] + "CheckIO" + text[position + 7:]
return final_result
Nov. 10, 2023
Comments: