Quick actions

cmd+k|ctrl+k

Navigation

Languages

IK injury table calculations

Snippet info

Language

Python

Visibility

public

Author

linus.aspelin

Created

2020-05-02T22:29:58Z

Updated

2020-05-02T22:29:58Z


def percent(title, *values):
    def success(number_of_dice, dice = []):
        def inner(number_of_dice, total):
            if number_of_dice:
                return sum(inner(number_of_dice-1, x+total) for x in range(1, 7))
            elif dice:
                return total in dice
            else:
                return True
                
        return inner(number_of_dice, 0)
    part = success(3, values)
    whole = success(3)
    print(f'{title}: {part}/{whole} = {part*1000//whole/10}%')
    return part/whole
     


total = sum([
    percent('death', 3),
    percent('death risk', 4, 6, 7, 8, 13, 14, 15, 17, 18),
    percent('injured', 5, 12, 16),
    percent('chill', 9, 10, 11),
])

if total != 1:
    print(f'\ntotal: {total*100}%')
INFO