Posted at

ランダム出力でポプテピピック

More than 1 year has passed since last update.


元ネタ

List<string> pptp = new List<string>(){"ポ", "プ", "テ", "ピピック"};

Random r = new Random();

Queue<string> queue = new Queue<string>();
Queue<string> resultQueue = new Queue<string>();

IEnumerable<string> PPTP(Random r)
{
while(true)
{
yield return pptp[r.Next(pptp.Count)];
}
}
void Main()
{

foreach(var elem in PPTP(r))
{
queue.Enqueue(elem);
resultQueue.Enqueue(elem);
if(queue.Count >= 4)
{
if(queue.Zip(pptp, (first, second) => first.Equals(second)).All(x => x))
{
Console.WriteLine(resultQueue);
break;
}
queue.Dequeue();
}
}
}