Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
8-liner: cleanest recursive solution in Clear category for Probably Dice by przemyslaw.daniel
from functools import lru_cache
@lru_cache(maxsize=None)
def probability(dice_number, sides, target):
if dice_number == 1:
return (1 <= target <= sides**dice_number)/sides
return sum([probability(dice_number-1, sides, target-x)
for x in range(1, sides+1)])/sides
Feb. 23, 2018
Comments: