def boyer_moore_preprocessing(pattern, alphabet_size=4):
    """
    Bad character rule used by Boyer-Moore algorithm:
    For each character x in the alphabet, let R(x) be the position of right-most occurrence of character x in P.
    R(x) is defined to be zero if x does not occur in P.
    """
    R = [0] * alphabet_size
    for i in range(len(pattern)):
        R[pattern[i]] = i
    return R