puzzles/roll-dice/roll_dice.py

9 lines
205 B
Python
Raw Normal View History

2024-04-02 21:01:09 +00:00
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("+"))
)