def biological_score(cluster):
    """
    Produces a measure of how biologically significant a given cluster in the 
    following manner. For every pair of active sites in the cluster, compute 
    a sequence similarity score between the two by dividing the number of residues
    the two sequences have in common by the length of the longer sequence. This 
    produces a number in the range [0, 1] for every pair of active sites. Average
    this score across the entire cluster and return as the biological score of the 
    cluster.

    Input: cluster (list of ActiveSites)

    Output: biological_score (float)
    """
    
    biological_score = 0.0
    # For every pair of active sites in the 
    # cluster, find the residues (types of residues) in their
    # sequences and count the number of residues that they
    # have in common. 
    for i in range(len(cluster)):
        for j in range(i + 1, len(cluster)):
            pair_score = 0.0
            residues_1 = []
            residues_2 = []
            for residue in cluster[i].residues:
                residues_1.append(residue.type)
            for residue in cluster[j].residues:
                residues_2.append(residue.type)

            for residue_type in set(residues_1):
                pair_score += residues_2.count(residue_type)

            # Divide the number of residues they have in common
            # by the length of the longer sequence
            pair_score = pair_score / max(len(residues_1), len(residues_2))

            biological_score += pair_score
            
    if len(cluster) > 1:
        biological_score = biological_score / (0.5 * (len(cluster) - 1) * len(cluster))


    return biological_score