2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

元ネタ

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();
		}
	}
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?