1using System;2using System.Collections.Generic;3using System.Linq;45namespace ConsoleApp1
6{7 class Program
8{9static Random random = new Random();1011staticvoidMain(string[] args)12{13 Console.WriteLine(CountDouble(ByShuffle,100000));14 Console.WriteLine(CountDouble(ByRetry,100000));15}1617staticintCountDouble(Func<int[]> func,int count)18{19return Enumerable
20.Repeat(0, count)21.Select(_ =>CountGroup(func()).Where(a => a ==2).Count())22.Sum();23}2425static IEnumerable<int>CountGroup(int[] array)26{27return array.GroupBy(a => a).Select(a => a.Count());28}2930staticint[]ByRetry()31{32while(true)33{34 var result = Enumerable
35.Repeat(0,10)36.Select(a => random.Next(10))37.ToArray();38if(CountGroup(result).Max()<3)39{40return result;41}42}43}4445staticint[]ByShuffle()46{47 var buffer = new int[20];48for(int i =0; i <20; i++)49{50 buffer[i]= i /2;51}52for(int i =19; i >=1; i--)53{54int j = random.Next(20);55(buffer[i], buffer[j])=(buffer[j], buffer[i]);56}57return buffer.Take(10).ToArray();58}59}60}