Is This Die Fair?
Tabletop Forge publishes board games, and shipments of dice keep arriving from new suppliers. Before a batch goes into twenty thousand boxes, somebody in the studio takes one die, rolls it a fixed number of times, and tallies how often each face came up. A perfectly fair die would be expected to show each face the same number of times, and that expected count comes with the tally sheet - it depends on how many rolls the tester did and how many faces the die has.
The studio tests four-sided and twenty-sided dice as well as ordinary cubes, so neither the number of faces nor the expected count can be assumed.
Task: Print the chi-square goodness-of-fit statistic for the tallies. The conventions: every face's expected count is the one supplied, because a fair die is the hypothesis being tested and nothing is being estimated from the tallies themselves; all faces contribute; no continuity correction is applied; and the value is printed raw, with no rounding at all.
Input
Two lines. The first holds the tallies, one whole number per face, separated by single spaces, in face order. The second holds the count each face was expected to show, a positive number.
Output
One line holding the chi-square statistic as a float, printed raw - 1.0, and 2.8000000000000003 when the arithmetic does not land cleanly.
Example:
Input:
8 12 9 11 10 10
10
Output:
1.0
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in