Estimating Pi With Random Points
Larkspur Labs sanity-checks a random-number source by making it estimate a number everybody already knows. Points are scattered across the square running from -1 to 1 on both axes, with every part of the square equally likely, and the share of them landing inside the circle of radius 1 centred on the square's middle is what carries the answer. The circle's area is pi and the square's is 4, so that share multiplied by 4 estimates pi. A point sitting exactly on the circle's edge counts as inside. The starter code has already set the stream from the seed and scattered the points, so the coordinates are ready in x and y.
Task: Print the estimate of pi.
Input
One line holding two integers separated by a space: the seed, then how many points to scatter.
Output
One line holding the estimate, written with exactly two decimal places.
Example:
Input:
1 10000
Output:
3.15
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