"""
Finding string patterns in a text

Copyright 2020, University of Freiburg

Philipp Schneider <philipp.schneider@cs.uni-freiburg.de>
"""


def compute_matches(t, p, b, mod):
    '''
        returns a list of indices where the pattern P can be found
        in the text T.

        Parameters:
            t - integer array representing the text
            p - integer array representing the search pattern
            b - base to which the integers in t and p should be considered
            mod - modulus that implicitely defines a hash function

        Returns:
            an array containing all positions where the
            pattern p begins in t
    '''


def read_input(filename):
    '''
        reads a string from a file and interprets it as two integer
        arrays representing a pattern and a text

        Parameter:
            filename - name of file

        Returns:
            pair (p, t) of array of integers representing the
            the pattern and the text respectively
    '''
    lines = ''
    with open(filename) as input:
        lines = input.read().splitlines()
    # first line contains pattern, second contains text
    chars_pattern = list(lines[0])
    chars_text = list(lines[1])
    # translate to unicode
    ints_pattern = [ord(chars_pattern[i]) for i in range(len(chars_pattern))]
    ints_text = [ord(chars_text[i]) for i in range(len(chars_text))]
    return (ints_pattern, ints_text)
