示例#1
0
        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--");
        }
示例#2
0
        /// <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);
        }
示例#3
0
        private static bool AskForCorrect(SolveInstance si, ref List <Tuple <int, string> > tl, Form1.ResultCallBack callback)
        {
            var ret = (from x in tl.OrderBy(s => s.Item1)
                       select si.SolvedStrings[x.Item2]).Aggregate("", (q1, q2) => q1 + q2 + " ");

            return(callback(ret));
        }