Exemple #1
0
        protected override void Solve(out string answer)
        {
            PentagonManager pentagonManager = new PentagonManager();

            //Generate numbers up to 5000
            long maxCount = 5000;

            foreach (long j in Enumerable64.Range(1, maxCount))
            {
                PentagonNumber pj = new PentagonNumber(j);
                pentagonManager.Add(pj);
            }
            long count        = maxCount * maxCount;
            long progressDone = 0;

            //Create all pairs 5000x5000
            Parallelization.GetParallelRanges(1, maxCount, 50).ForAll(sequence =>
            {
                foreach (long j in sequence)
                {
                    foreach (long k in Enumerable64.Range(1, maxCount))
                    {
                        PentagonPair pjk = pentagonManager.CreatePair(j, k);
                        if (pentagonManager.IsSumPentagonal(pjk))
                        {
                            if (pentagonManager.IsDifPentagonal(pjk))
                            {
                                lock (pentagonManager)
                                {
                                    pentagonManager.StorePair(pjk);
                                }
                            }
                        }
                        lock (this)
                        {
                            progressDone++;
                            if (progressDone % 100_000 == 0)
                            {
                                int percent = (int)(progressDone * 100.0 / count);
                                UpdateProgress($"Pairs checked out of {count}: Done {percent}%. Hits: {pentagonManager.storedPairs.Count}...");
                            }
                        }
                    }
                }
            });
            var solution = pentagonManager.storedPairs.OrderBy(pair => pair.AbsDifValue).First();

            answer = $"Candiates = {pentagonManager.storedPairs.Count}, D = {solution.AbsDifValue}.";
        }
Exemple #2
0
 internal void Add(PentagonNumber pj)
 {
     dictionary.Add(pj.Number, pj);
 }
Exemple #3
0
 public PentagonPair(PentagonNumber pj, PentagonNumber pk)
 {
     Pj = pj;
     Pk = pk;
 }