puzzles/roll-dice/roll_dice.py
Zoé Cassiopée Gauthier 7e4f02547b Initial commit
2024-04-02 17:01:09 -04:00

9 lines
205 B
Python

import random
def roll_dice(spec):
return sum(
sum(random.randint(1, int(a)) for _ in range(int(b))) if b else int(a)
for a, _, b in (s.partition("d") for s in spec.split("+"))
)