def score_foundation_balance(table):
    """
    Finds the lowest card that has been unlocked in all foundations and
    returns a factorial score for it, or 0.
    """
    # What's the lowest card on any of the foundations?    
    lowest_unlocked = min(len(f.cards) for f in table.foundations)
    # For klondike, this conveniently means that a len of 0 means empty and a
    # len of 1 means it contains the ace, etc.
    return sum(range(1, lowest_unlocked + 1)) if lowest_unlocked else 0