Пример #1
0
        private void popFigNums()
        {
            foreach (FigEnum k in Enum.GetValues(typeof(FigEnum)))
            {
                int n = 1;
                // skip to 1001.
                while (getFigurateNum(k, ++n) < 1000)
                {
                    ;
                }
                // now start saving them.
                int p = getFigurateNum(k, n);
                //Console.WriteLine("{0}, {1} -> {2}", k, n, p);
                while (p < 10000)
                {
                    var fn = myFigNums.FirstOrDefault(x => x.Num == p);
                    if (fn == null)
                    {
                        fn = new FigurateNum(p);
                        myFigNums.Add(fn);
                    }
                    fn.setIsFig(k, true);

                    n++;
                    p = getFigurateNum(k, n);
                }
            }
        }
Пример #2
0
        private long processSubset(List <FigurateNum> candidateSet)
        {
            if (candidateSet.Count < 6)
            {
                long        rv = 0;
                FigurateNum c1 = candidateSet.Last();
                var         q2 =
                    from x in myFigNums
                    where x.getFirstTwoDigits() == c1.getLastTwoDigits() &&
                    !candidateSet.Any(c => c.Num == x.Num)
                    select x;
                foreach (var c2 in q2)
                {
                    List <FigurateNum> nextCandidateSet = new List <FigurateNum>(candidateSet);
                    nextCandidateSet.Add(c2);
                    long n = processSubset(nextCandidateSet);
                    if (n > 0)
                    {
                        rv = n;
                    }
                }
                return(rv);
            }
            else
            {
                // we have all 6 numbers. check and see if we've got what we need...
                // check wrap from #6 to #1...
                FigurateNum c1 = candidateSet.First();
                FigurateNum c6 = candidateSet.Last();
                if (c6.getLastTwoDigits() != c1.getFirstTwoDigits())
                {
                    return(0);
                }
                // do we have one of each?
                bool gotIt = true;
                foreach (FigEnum k in Enum.GetValues(typeof(FigEnum)))
                {
                    if (!candidateSet.Any(c => c.getHighestFig() == k))
                    {
                        gotIt = false;
                    }
                }

                if (gotIt)
                {
                    foreach (var c in candidateSet)
                    {
                        Console.WriteLine(c);
                    }
                    Console.WriteLine("-----");
                    return(candidateSet.Sum(c => c.Num));
                }
                return(0);   // nope.
            }
        }