DEV Community

Discussion on: Daily Challenge #41 - Greed is Good

Collapse
 
splinter98 profile image
splinter98

my attempt using Python:

from collections import Counter


def score(values):
    """
    Greed is good scoring

    >>> score((5,1,3,4,1))
    250
    >>> score((1,1,1,3,1))
    1100
    >>> score((2,4,4,5,4))
    450
    """
    count = Counter(values)
    score = 0
    for value, amount in count.items():
        if value > 6:
            raise ValueError("Invalid dice value")
        if value == 1:
            value = 10
        trip, left = divmod(amount, 3)
        score += trip * value * 100
        if value in (10, 5):
            score += left * value * 10
    return score


if __name__ == "__main__":
    import doctest

    doctest.testmod(verbose=True)