import re


def make_consts_consecutive(s):
    """
    The given phenotype will have zero or more occurrences of each const c[0],
    c[1], etc. But eg it might have c[7], but no c[0]. We need to remap, eg:
        7 -> 0
        9 -> 1
    so that we just have c[0], c[1], etc.
    
    :param s: A given phenotype string.
    :return: The phenotype string but with consecutive constants.
    """

    p = r"c\[(\d+)\]"
    # find the consts, extract idxs as ints, unique-ify and sort
    const_idxs = sorted(map(int, set(re.findall(p, s))))

    for i, j in enumerate(const_idxs):
        ci = "c[%d]" % i
        cj = "c[%d]" % j
        s = s.replace(cj, ci)

    return s, len(const_idxs)