Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Program
  6. {
  7.     static Random rng = new Random();
  8.  
  9.     public static void Main()
  10.     {
  11.         var numberSetsCreated = 0;
  12.         while (true)
  13.         {
  14.             numberSetsCreated++;
  15.             var randomNumbers = GenerateRandomSet(200);
  16.  
  17.             var testResults = InterestingDistributionsTest(randomNumbers, 0.07).ToList();
  18.             foreach (var interestingThing in testResults)
  19.             {
  20.                 Console.ForegroundColor = ConsoleColor.Green;
  21.                 Console.WriteLine($"Dataset { numberSetsCreated } - { interestingThing }");
  22.             }
  23.  
  24.             var testResults2 = InterestingStreaksTest(randomNumbers, 7);
  25.             foreach (var interestingThing in testResults2)
  26.             {
  27.                 Console.ForegroundColor = ConsoleColor.Yellow;
  28.                 Console.WriteLine($"Dataset { numberSetsCreated } - { interestingThing }");
  29.             }
  30.  
  31.             var testResults3 = InterestingGapsTest(randomNumbers, 70);
  32.             foreach (var interestingThing in testResults3)
  33.             {
  34.                 Console.ForegroundColor = ConsoleColor.Cyan;
  35.                 Console.WriteLine($"Dataset { numberSetsCreated } - { interestingThing }");
  36.             }
  37.         }
  38.     }
  39.  
  40.  
  41.     public static IEnumerable<string> InterestingDistributionsTest(IEnumerable<int> randomSet, double percentInteresting)
  42.     {
  43.         var setSize = randomSet.Count();
  44.         var analysis = randomSet.GroupBy(quality => quality);
  45.         return analysis
  46.             .Where(group => group.Key != 100 && group.Count() / (double) setSize <= percentInteresting)
  47.             .Select(group => $"{ group.Key }% quality has only generated { (int)((group.Count() / (double)setSize) * 100) }% in this set ({ group.Count() })");
  48.     }
  49.     public static IEnumerable<string> InterestingStreaksTest(IEnumerable<int> randomSet, int lengthInteresting)
  50.     {
  51.         var largestStreaks = new Dictionary<int, int>()
  52.         {
  53.             { 94, 0 },
  54.             { 95, 0 },
  55.             { 96, 0 },
  56.             { 97, 0 },
  57.             { 98, 0 },
  58.             { 99, 0 },
  59.             { 100, 0 }
  60.         };
  61.         var previousQuality = 0;
  62.         var currentSteakLength = 0;
  63.         foreach (var quality in randomSet)
  64.         {
  65.             if (quality == previousQuality)
  66.             {
  67.                 currentSteakLength++;
  68.             }
  69.             else
  70.             {
  71.                 if (previousQuality > 0 && largestStreaks[quality] < currentSteakLength)
  72.                 {
  73.                     largestStreaks[quality] = currentSteakLength;
  74.                 }
  75.                 previousQuality = quality;
  76.                 currentSteakLength = 1;
  77.             }
  78.         }
  79.         return largestStreaks
  80.             .Where(streak => streak.Value >= lengthInteresting)
  81.             .Select(streak => $"{ streak.Key }% quality gems had a long streak in this set ({ streak.Value })");
  82.     }
  83.     public static IEnumerable<string> InterestingGapsTest(IEnumerable<int> randomSet, int lengthInteresting)
  84.     {
  85.         var largestGaps = new Dictionary<int, int>()
  86.         {
  87.             { 94, 0 },
  88.             { 95, 0 },
  89.             { 96, 0 },
  90.             { 97, 0 },
  91.             { 98, 0 },
  92.             { 99, 0 },
  93.             { 100, 0 }
  94.         };
  95.  
  96.         var lastSeen = new Dictionary<int, int>()
  97.         {
  98.             { 94, 0 },
  99.             { 95, 0 },
  100.             { 96, 0 },
  101.             { 97, 0 },
  102.             { 98, 0 },
  103.             { 99, 0 },
  104.             { 100, 0 }
  105.         };
  106.  
  107.         var position = 0;
  108.         foreach (var quality in randomSet)
  109.         {
  110.             position++;
  111.             var currentLargest = largestGaps[quality];
  112.             var seen = lastSeen[quality];
  113.             if (position - seen > currentLargest)
  114.             {
  115.                 largestGaps[quality] = position - seen;
  116.             }
  117.             lastSeen[quality] = position;
  118.         }
  119.         return largestGaps
  120.             .Where(gap => gap.Value >= lengthInteresting && gap.Key != 100)
  121.             .Select(gap => $"{ gap.Key }% has just been seen again after a long gap ({ gap.Value })");
  122.     }
  123.  
  124.     public static IEnumerable<int> GenerateRandomSet(int size) => Enumerable.Range(0, size).Select(r => GetQuality());
  125.  
  126.     public static int GetQuality()
  127.     {
  128.         if (Chance(2))
  129.         {
  130.             return 100; // 2% chance for master piece
  131.         }
  132.         return 94 + Random(0, 5);
  133.     }
  134.  
  135.     public static bool Chance(int chancePercent)
  136.     {
  137.         return chancePercent >= Random(0, 100);
  138.     }
  139.  
  140.     public static int Random(int min, int max)
  141.     {
  142.         return rng.Next(min, max + 1);
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement