def generate_all_masks(length, masks=[""]):
    """Recursively generate a list of all possible masks of given length.
    Masks consist of the following symbols (similar to the Wordle game):
    0 -- green tile (correct digit and correct position);
    1 -- yellow tile (correct digit but wrong position);
    2 -- gray tile (wrong digit)."""
    if len(masks[0]) == length:
        return masks
    else:
        new_masks = []
        for mask in masks:
            new_masks.extend([mask+"2", mask+"1", mask+"0"])
        return generate_all_masks(length, new_masks)