def score(peptide, perfect_spectrum, table):
    actual_spectrum = generate_cyclo_spectrum(peptide, table)
    result_score = 0
    i1 = 0
    i2 = 0
    actual_spectrum = map(int, actual_spectrum)
    perfect_spectrum = map(int, perfect_spectrum)
    while i1 < len(actual_spectrum) and i2 < len(perfect_spectrum):
        if actual_spectrum[i1] == perfect_spectrum[i2]:
            result_score += 1
            i1 += 1
            i2 += 1
        elif actual_spectrum[i1] > perfect_spectrum[i2]:
            i2 += 1
        elif actual_spectrum[i1] < perfect_spectrum[i2]:
            i1 += 1
    return result_score
def cyclo_sequence(spectrum, table):
    leaderboard = ['']
    leader_peptides = ['']
    parent_mass = spectrum[-1]
    while len(leaderboard) > 0:
        new_leaderboard = []
        map(lambda x: new_leaderboard.extend([peptide + x for peptide in leaderboard]), LETTERS)
        leaderboard = new_leaderboard
        stuff_to_remove = []
        for peptide in leaderboard:
            if weight(peptide, table) == parent_mass:
                if generate_cyclo_spectrum(peptide, table) == spectrum:
                    leader_peptides.append(peptide)
                stuff_to_remove.append(peptide)
            elif not is_spectrum_consistent(generate_linear_spectrum(peptide, table), perfect_spectrum):
                stuff_to_remove.append(peptide)
        [leaderboard.remove(x) for x in stuff_to_remove]

    return leader_peptides