Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- static Random rng = new Random();
- public static void Main()
- {
- var numberSetsCreated = 0;
- while (true)
- {
- numberSetsCreated++;
- var randomNumbers = GenerateRandomSet(200);
- var testResults = InterestingDistributionsTest(randomNumbers, 0.07).ToList();
- foreach (var interestingThing in testResults)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine($"Dataset { numberSetsCreated } - { interestingThing }");
- }
- var testResults2 = InterestingStreaksTest(randomNumbers, 7);
- foreach (var interestingThing in testResults2)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine($"Dataset { numberSetsCreated } - { interestingThing }");
- }
- var testResults3 = InterestingGapsTest(randomNumbers, 70);
- foreach (var interestingThing in testResults3)
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine($"Dataset { numberSetsCreated } - { interestingThing }");
- }
- }
- }
- public static IEnumerable<string> InterestingDistributionsTest(IEnumerable<int> randomSet, double percentInteresting)
- {
- var setSize = randomSet.Count();
- var analysis = randomSet.GroupBy(quality => quality);
- return analysis
- .Where(group => group.Key != 100 && group.Count() / (double) setSize <= percentInteresting)
- .Select(group => $"{ group.Key }% quality has only generated { (int)((group.Count() / (double)setSize) * 100) }% in this set ({ group.Count() })");
- }
- public static IEnumerable<string> InterestingStreaksTest(IEnumerable<int> randomSet, int lengthInteresting)
- {
- var largestStreaks = new Dictionary<int, int>()
- {
- { 94, 0 },
- { 95, 0 },
- { 96, 0 },
- { 97, 0 },
- { 98, 0 },
- { 99, 0 },
- { 100, 0 }
- };
- var previousQuality = 0;
- var currentSteakLength = 0;
- foreach (var quality in randomSet)
- {
- if (quality == previousQuality)
- {
- currentSteakLength++;
- }
- else
- {
- if (previousQuality > 0 && largestStreaks[quality] < currentSteakLength)
- {
- largestStreaks[quality] = currentSteakLength;
- }
- previousQuality = quality;
- currentSteakLength = 1;
- }
- }
- return largestStreaks
- .Where(streak => streak.Value >= lengthInteresting)
- .Select(streak => $"{ streak.Key }% quality gems had a long streak in this set ({ streak.Value })");
- }
- public static IEnumerable<string> InterestingGapsTest(IEnumerable<int> randomSet, int lengthInteresting)
- {
- var largestGaps = new Dictionary<int, int>()
- {
- { 94, 0 },
- { 95, 0 },
- { 96, 0 },
- { 97, 0 },
- { 98, 0 },
- { 99, 0 },
- { 100, 0 }
- };
- var lastSeen = new Dictionary<int, int>()
- {
- { 94, 0 },
- { 95, 0 },
- { 96, 0 },
- { 97, 0 },
- { 98, 0 },
- { 99, 0 },
- { 100, 0 }
- };
- var position = 0;
- foreach (var quality in randomSet)
- {
- position++;
- var currentLargest = largestGaps[quality];
- var seen = lastSeen[quality];
- if (position - seen > currentLargest)
- {
- largestGaps[quality] = position - seen;
- }
- lastSeen[quality] = position;
- }
- return largestGaps
- .Where(gap => gap.Value >= lengthInteresting && gap.Key != 100)
- .Select(gap => $"{ gap.Key }% has just been seen again after a long gap ({ gap.Value })");
- }
- public static IEnumerable<int> GenerateRandomSet(int size) => Enumerable.Range(0, size).Select(r => GetQuality());
- public static int GetQuality()
- {
- if (Chance(2))
- {
- return 100; // 2% chance for master piece
- }
- return 94 + Random(0, 5);
- }
- public static bool Chance(int chancePercent)
- {
- return chancePercent >= Random(0, 100);
- }
- public static int Random(int min, int max)
- {
- return rng.Next(min, max + 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement