public void TestCreate()
        {
            var arr = new List <int>()
            {
                1, 2, 3, 4
            };
            var nodes = FactorGenerator.Create(arr);

            Assert.IsNotNull(nodes);
            Assert.IsTrue(nodes.Count == 6);
            Assert.IsTrue(nodes[0].Left != null && string.Join(",", nodes[0].Left) == "1,2");
            Assert.IsTrue(nodes[0].Right != null && string.Join(",", nodes[0].Right) == "3,4");

            Assert.IsTrue(nodes[1].Left != null && string.Join(",", nodes[1].Left) == "3,4");
            Assert.IsTrue(nodes[1].Right != null && string.Join(",", nodes[1].Right) == "1,2");

            Assert.IsTrue(nodes[2].Left != null && string.Join(",", nodes[2].Left) == "1,3");
            Assert.IsTrue(nodes[2].Right != null && string.Join(",", nodes[2].Right) == "2,4");

            Assert.IsTrue(nodes[3].Left != null && string.Join(",", nodes[3].Left) == "2,4");
            Assert.IsTrue(nodes[3].Right != null && string.Join(",", nodes[3].Right) == "1,3");

            Assert.IsTrue(nodes[4].Left != null && string.Join(",", nodes[4].Left) == "1,4");
            Assert.IsTrue(nodes[4].Right != null && string.Join(",", nodes[4].Right) == "2,3");

            Assert.IsTrue(nodes[5].Left != null && string.Join(",", nodes[5].Left) == "2,3");
            Assert.IsTrue(nodes[5].Right != null && string.Join(",", nodes[5].Right) == "1,4");
        }
        public void TestMethod_Analyse_Five_Digit_By_Random()
        {
            var numbers = GetTestNumbers(0, 5, 100000);

            //因子
            var factors = FactorGenerator.Create(new List <byte> {
                0, 1, 2, 3, 4
            }.ToList());

            var watch = new Stopwatch();

            watch.Start();
            var resultString     = new StringBuilder();
            var hasCount         = 0;
            var resultCount      = 0;
            var defaultTakeCount = 101;

            var curTakeCount = defaultTakeCount;

            for (var i = 0; i < 2500; i++)
            {
                var number     = numbers[i];
                var curNumbers = numbers.Skip(i + 1).Take(curTakeCount).ToList();
                curNumbers.Reverse();
                var dto = new FactorsTrendAnalyseDto <byte>
                {
                    AddConsecutiveTimes            = 2,
                    AddInterval                    = 1,
                    Numbers                        = curNumbers,
                    AnalyseHistoricalTrendEndIndex = 100,
                    Factors                        = factors
                };

                //var dto = new MarkSixAnalyseSpecifiedLocationDto { Location = 7, StartTimes = records[i].StartTimes, TensAllowMinFactorCurrentConsecutiveTimes = 6, TensAllowMaxInterval = -1, TensAroundCount = 200, TensNumbersTailCutCount = 6 };
                var result  = TestAnalyse(dto);
                var success = false;
                if (result.Count > 0)
                {
                    resultCount++;
                    if (result.Contains(number))
                    {
                        success = true;
                    }
                }
                if (success)
                {
                    hasCount++;
                    resultString.AppendLine("期次:" + i + ",号码:" + number + ",分析结果:" + (success ? "-Yes- " : "      ") + string.Join(";", result));
                    curTakeCount = defaultTakeCount;
                }
                else
                {
                    curTakeCount++;
                }
            }
            watch.Stop();
            var usedSeconds = watch.ElapsedMilliseconds / 1000;
            var str         = resultString.ToString();
        }
Beispiel #3
0
 public long SumOfProperDivisors(long n)
 {
     long result;
     if (!_cache.TryGetValue(n, out result))
     {
         _cache[n] = result = new FactorGenerator(n)
             .SkipLast(1)
             .Sum();
     }
     return result;
 }
        public void TestCreate_Length_Three()
        {
            var arr = new List <int>()
            {
                1, 2, 3
            };
            var nodes = FactorGenerator.Create(arr, 1, false);

            Assert.IsNotNull(nodes);
            Assert.IsTrue(nodes.Count == 4);
            Assert.IsTrue(nodes[0].Left != null && string.Join(",", nodes[0].Left) == "1,2");
            Assert.IsTrue(nodes[0].Right != null && string.Join(",", nodes[0].Right) == "3");

            Assert.IsTrue(nodes[1].Left != null && string.Join(",", nodes[1].Left) == "3");
            Assert.IsTrue(nodes[1].Right != null && string.Join(",", nodes[1].Right) == "1,2");

            Assert.IsTrue(nodes[2].Left != null && string.Join(",", nodes[2].Left) == "1,3");
            Assert.IsTrue(nodes[2].Right != null && string.Join(",", nodes[2].Right) == "2");

            Assert.IsTrue(nodes[3].Left != null && string.Join(",", nodes[3].Left) == "2");
            Assert.IsTrue(nodes[3].Right != null && string.Join(",", nodes[3].Right) == "1,3");
        }
Beispiel #5
0
        public void TestMethod_Analyse_Ten_Digit_By_Random_ASC()
        {
            var numbers = GetTestNumbers(0, 10, 100000);
            //因子
            var factors = FactorGenerator.Create(new List <byte> {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9
            }.ToList());

            var watch = new Stopwatch();

            watch.Start();
            var resultString     = new StringBuilder();
            var defaultTakeCount = 1000;


            var testCount = 2500;
            var trend     = new FactorTrend();
            var factorsTrendCorrectRates = new Dictionary <Factor <byte>, List <FactorTrendCorrectRate> >();

            var firstrFactor = factors[0];

            foreach (var factor in factors)
            {
                var strFactor         = string.Join(",", factor.Right);
                var trendCorrectRates = new List <FactorTrendCorrectRate>();
                for (var c = 3; c < 22; c++)
                {
                    for (var interval = 0; interval > -9; interval--)
                    {
                        var hasCount    = 0;
                        var resultCount = 0;

                        for (var i = testCount; i >= 0; i--)
                        {
                            var number     = numbers[i];
                            var curNumbers = numbers.Skip(i + 1).Take(defaultTakeCount).ToList();
                            curNumbers.Reverse();

                            var dto = new FactorTrendAnalyseDto <byte>
                            {
                                AddConsecutiveTimes            = c,
                                AddInterval                    = interval,
                                Numbers                        = curNumbers,
                                AnalyseHistoricalTrendEndIndex = 1,
                                Factor = factor
                            };
                            var result  = trend.Analyse1(dto);
                            var success = false;
                            if (result == null)
                            {
                                continue;
                            }
                            if (result.Count > 0)
                            {
                                resultCount++;
                                if (result.Contains(number))
                                {
                                    success = true;
                                }
                            }
                            if (success)
                            {
                                hasCount++;
                            }
                        }
                        var correctRate = resultCount == 0 ? 0 : (double)hasCount / resultCount;
                        if (correctRate == 1)
                        {
                            trendCorrectRates.Add(new FactorTrendCorrectRate
                            {
                                AllowConsecutiveTimes = c,
                                AllowInterval         = interval,
                                AnalyticalCount       = resultCount,
                                CorrectCount          = hasCount,
                                TypeDescription       = strFactor,
                                CorrectRate           = correctRate
                            });
                        }
                    }
                }

                if (trendCorrectRates.Count > 0)
                {
                    factorsTrendCorrectRates.Add(factor, trendCorrectRates);
                }
                break;
            }
            watch.Stop();
            var usedSeconds = watch.ElapsedMilliseconds / 1000;

            var realHasCount    = 0;
            var realResultCount = 0;

            var consecutiveTimes = 12;
            var curInterval      = -2;

            testCount = 99000;
            for (var i = testCount; i >= 0; i--)
            {
                var number     = numbers[i];
                var curNumbers = numbers.Skip(i + 1).Take(200).ToList();
                curNumbers.Reverse();
                var dto = new FactorTrendAnalyseDto <byte>
                {
                    AddConsecutiveTimes            = consecutiveTimes,
                    AddInterval                    = curInterval,
                    Numbers                        = curNumbers,
                    AnalyseHistoricalTrendEndIndex = 1,
                    Factor = firstrFactor
                };
                var result  = trend.Analyse1(dto);
                var success = false;
                if (result == null)
                {
                    continue;
                }
                if (result.Count > 0)
                {
                    realResultCount++;
                    if (result.Contains(number))
                    {
                        success = true;
                    }
                }
                if (success)
                {
                    realHasCount++;
                    resultString.AppendLine("期次:" + i + ",号码:" + number + ",分析结果:" + (success ? "-Yes- " : "      ") + string.Join(";", result));
                }
            }
            watch.Stop();
            usedSeconds = watch.ElapsedMilliseconds / 1000;


            var str = resultString.ToString();
        }