using System; using System.Collections.Generic; using System.Text; using Sprache; using System.IO;
publicclassZundokoGenerator { Random _random = new Random(); public IEnumerator<string> RandomZunDoko() { for (;;) { yieldreturn _random.Next(0, 2) == 0 ? "ズン" : "ドコ"; } } }
publicstaticclassKiyoshiParser { publicstaticreadonly Parser<string> zun = from txt in Parse.String("ズン").Text() select txt; publicstaticreadonly Parser<string> doko = from txt in Parse.String("ドコ").Text() select txt; publicstaticreadonly Parser<string> zzzd = from z0 in zun from z1 in zun from z2 in zun from z3 in zun from dk in doko select"キヨシ"; }
classProgram { staticvoidMain() { var zdg = new ZundokoGenerator().RandomZunDoko(); var sb = new StringBuilder(); int count = 0; for (;;) { sb.Clear(); for (int i = 0; i < 5; ++i) { zdg.MoveNext(); sb.Append(zdg.Current); } ++count; try { var kys = KiyoshiParser.zzzd.Parse(sb.ToString()); Console.WriteLine(sb.ToString() + kys); Console.WriteLine(count + "回ズンドコしました"); break; } catch (Sprache.ParseException) { Console.WriteLine(sb.ToString()); } } } }