Exemple #1
0
def task3():
    text = get_and_prepare_text('haystack.txt')

    count = search_patterns(text, ['tt', 'hh'], print_output=True)
    print("Pattern 'th' total:", count)
    print("-----------------------------")
    count = search_patterns(text, ['tt', '  ', 'hh'], print_output=True)
    print("Pattern 't h' total:", count)
Exemple #2
0
def task2():
    text = get_and_prepare_text('haystack.txt')

    chars = get_all_letters(text)
    total = 0

    for letter in chars:
        count = search_patterns(text, [letter + letter], False)
        if count and letter != '#':
            print("Letter ", letter, ":", count)
            total += count
    print("Total: ", total)
Exemple #3
0
def divide_and_search(pieces, text, pattern):
    length = len(text)
    total_build_time = 0
    total_search_time = 0
    print("----------------------------------")
    print("Pieces:", pieces)
    for i in range(pieces):
        begin = int(i * length / pieces)
        end = min(int((i + 1) * length / pieces), length)
        _, build_time, search_time = search_patterns(text[begin:end],
                                                     pattern,
                                                     return_time=True)
        total_build_time += build_time
        total_search_time += search_time
    print("\nTotal build time:", total_build_time)
    print("Total search time:", total_search_time)
Exemple #4
0
def check_time(text, row, col):
    row_pattern = row * 'a'
    pattern = [row_pattern for _ in range(col)]
    print("Row number:", row, ", Column number:", col)
    search_patterns(text, pattern, print_time=True)
    print()
Exemple #5
0
def search_letter_in_image(image, print_output=False):
    return lambda x: search_patterns(image,
                                     img_fun.get_patterns_columns(x, image),
                                     print_output=print_output)