def score(ranges, tagmap):
    """we want to maximise this: the GM of the areas covered"""
    score = 0
    if not tagmap:
        return 0
    for tag, (rmin, rmax) in ranges.items():
        amin, amax = tagmap[tag]
        try:
            score += 1 / ((rmax - rmin) / float(amax - amin))
        except ZeroDivisionError:
            score += 1
    numaxes = len(dict.fromkeys(list(tagmap.values())))
    wastedspace = (numaxes - 1) * 5
    return (100 - wastedspace) / score / numaxes
