import re
import time

SS = str(13**100500)
print(len(SS))
SUB = '637036977498347229246'
TEMPLATE = "63@036@7749@347@29@46"

time_start = time.monotonic()

result = SS.find(SUB)
time_end = time.monotonic()
print(f"result: {result}, str search worktime: {1000 * (time_end - time_start):.3f}ms")

def check_pattern(s, template):
    # first, split strings to lists of symbols
    m = [*s]
    t = [*template]
    at = [index for index, symbol in enumerate(t) if symbol == '@']
    for shift in range(len(m) - len(t) + 1):
        sub_array = m[shift: shift + len(t)]
        for at_index in at:
            sub_array[at_index] = '@'
        if sub_array == t:
            return shift
    return -1

def check_pattern_2(s, template):
    # first, split strings to lists of symbols
    m = [*s]
    t = [*template]
    MM = [(index, symbol) for index, symbol in enumerate(t) if symbol != '@']
    for shift in range(len(m) - len(t) + 1):
        t_pass = True
        for kk, symbol in MM:
            if m[shift + kk] != symbol:
                t_pass = False
                break
        if t_pass:
            return shift

    return -1

def check_pattern_re(s, template):
    res = re.findall(template.replace('@', '.'), s)
    return s.find(res[0]) if res else -1

time_start = time.monotonic()
result = check_pattern_2(SS, TEMPLATE)
time_end = time.monotonic()

worktime = 1000 * (time_end - time_start)
print(f"result: {result}, worktime: {worktime:.3f}ms")
