Created
August 4, 2024 21:38
-
-
Save ddjerqq/eb487d3f8157c4362d9f106de622cb65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var size = Random.Shared.Next(0, 1_000_000); | |
var numbers = Enumerable.Range(0, size).ToArray(); | |
Random.Shared.Shuffle(numbers); | |
// we are allowed a total of 5 observations, we must use | |
// the average gap method to approximate the number of elements | |
var observationCount = 100; | |
var observations = numbers.Take(observationCount).ToArray(); | |
var maxObserved = observations.Max(); | |
// k is sample count | |
// x is the max number observed | |
// x + (x - k) / k | |
var total = maxObserved + (maxObserved - observationCount) / observationCount; | |
Console.WriteLine($"Sample count: {observationCount}"); | |
Console.WriteLine($"Observations: {string.Join(", ", observations)}"); | |
Console.WriteLine($"Estimated total: {total}"); | |
Console.WriteLine($"Actual total: {size}"); | |
Console.WriteLine($"Error: {Math.Abs(size - total)}"); | |
Console.WriteLine($"Error %: {MathF.Abs(size - total) / size:P2}"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment