private static void OutputResult(SolveInstance si, Form1.IncrementCounter ic) { if (ic == null) { return; } String ret = GetResultText(si); ic(ret); }
public static void Solve(string words, Form1.ResultCallBack callback, Form1.IncrementCounter ic) { callback("--START--"); var si = new SolveInstance(); var s = words.Split(new[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); var tl = s.Select((t, a) => new Tuple <int, string>(a, t)).ToList(); //shortest first foreach (var s1 in tl.OrderByDescending(s1 => s1.Item2.Length)) { if (si.SolvedStrings.ContainsKey(s1.Item2) == false) { si.SolvedStrings.Add(s1.Item2, null); } } Solve(si, ref tl, callback, ic); callback("--FINISHED--"); }
/// <summary> /// tuple enc unenc /// </summary> /// <param name="si"></param> /// <returns></returns> private static IEnumerable <Tuple <string, string> > Solve(SolveInstance si, ref List <Tuple <int, string> > tl, Form1.ResultCallBack callback, Form1.IncrementCounter ic) { var left = si.SolvedStrings.Where(s => s.Value == null); var lc = left.Count(); if (lc == 0) { if (AskForCorrect(si, ref tl, callback) == false) { return(null); } return(new List <Tuple <string, string> >()); } var en = left.First().Key; foreach (var s in Unencrypt(si, en)) { if (ic != null) { OutputResult(s.Item1, ic); } var retr = Solve(s.Item1, ref tl, callback, ic); if (retr != null) { var r = new Tuple <string, string>(en, s.Item2); var ret = new List <Tuple <string, string> >(); ret.Add(r); ret.AddRange(retr); return(ret); } } return(null); }