Returns probability that Pyramidal Peter beats Cubic Colin rounded to seven decimal places in the form 0.abcdefg >>> solution() 0.5731441
()
| 39 | |
| 40 | |
| 41 | def solution() -> float: |
| 42 | """ |
| 43 | Returns probability that Pyramidal Peter beats Cubic Colin |
| 44 | rounded to seven decimal places in the form 0.abcdefg |
| 45 | |
| 46 | >>> solution() |
| 47 | 0.5731441 |
| 48 | """ |
| 49 | |
| 50 | peter_totals_frequencies = total_frequency_distribution( |
| 51 | sides_number=4, dice_number=9 |
| 52 | ) |
| 53 | colin_totals_frequencies = total_frequency_distribution( |
| 54 | sides_number=6, dice_number=6 |
| 55 | ) |
| 56 | |
| 57 | peter_wins_count = 0 |
| 58 | min_peter_total = 9 |
| 59 | max_peter_total = 4 * 9 |
| 60 | min_colin_total = 6 |
| 61 | for peter_total in range(min_peter_total, max_peter_total + 1): |
| 62 | peter_wins_count += peter_totals_frequencies[peter_total] * sum( |
| 63 | colin_totals_frequencies[min_colin_total:peter_total] |
| 64 | ) |
| 65 | |
| 66 | total_games_number = (4**9) * (6**6) |
| 67 | peter_win_probability = peter_wins_count / total_games_number |
| 68 | |
| 69 | rounded_peter_win_probability = round(peter_win_probability, ndigits=7) |
| 70 | |
| 71 | return rounded_peter_win_probability |
| 72 | |
| 73 | |
| 74 | if __name__ == "__main__": |
no test coverage detected