def update_hash(n_pattern: int, base: int, prime: int):
    """Generate function to modify current hash."""

    diff = base ** (n_pattern - 1)

    def inner(c_old: str, c_new: str, h: int):
        """Update current hash."""

        h -= ord(c_old) * diff
        h *= base
        h += ord(c_new)
        h %= prime

        return h

    return inner