def find_recipes_2(pattern):
    """
    Calculate the number of recipes in the sequence before the given pattern appears.
    :param pattern: the pattern to identify
    :return: the number of recipes to the left of the pattern

    >>> find_recipes_2('51589')
    9
    >>> find_recipes_2('01245')
    5
    >>> find_recipes_2('92510')
    18
    >>> find_recipes_2('59414')
    2018
    """
    # Make rounds into a list of digits.
    pattern_len = len(pattern)
    digits = [int(i) for i in pattern]
    last_digits = []
    recipes = [3, 7]
    elf1 = 0
    elf2 = 1
    looking = True
    while looking:
        new_recipe = recipes[elf1] + recipes[elf2]
        for i in str(new_recipe):
            if len(last_digits) == pattern_len:
                last_digits.pop(0)
            recipes.append(int(i))
            last_digits.append(int(i))

            # We have to check here as it could appear in the middle of adding new recipes.
            # In fact, in my case, it does.
            if last_digits == digits:
                looking = False
                break
        elf1 = (elf1 + recipes[elf1] + 1) % len(recipes)
        elf2 = (elf2 + recipes[elf2] + 1) % len(recipes)
    return len(recipes) - len(digits)