Ejemplo n.º 1
0
        public static void TestSomething10()
        {
            HashSet <int>         seenAmplitudes = new HashSet <int>();
            Queue <PendulumSwing> queue          = new Queue <PendulumSwing>();

            int           startingAmplitude     = -43470; // index 315
            PendulumSwing startingPendulumSwing = new PendulumSwing(startingAmplitude, 0, null);

            queue.Enqueue(startingPendulumSwing);
            seenAmplitudes.Add(startingPendulumSwing.Amplitude);

            while (queue.Count > 0)
            {
                PendulumSwing        dequeue    = queue.Dequeue();
                List <PendulumSwing> successors = dequeue.GetSuccessors();
                foreach (PendulumSwing pendulumSwing in successors)
                {
                    if (pendulumSwing.Amplitude == -57330)
                    {
                        InfoForm.ShowValue(pendulumSwing);
                        return;
                    }
                    if (seenAmplitudes.Contains(pendulumSwing.Amplitude))
                    {
                        continue;
                    }
                    queue.Enqueue(pendulumSwing);
                    seenAmplitudes.Add(pendulumSwing.Amplitude);
                }
            }
        }
Ejemplo n.º 2
0
        public void FillInExtended()
        {
            int range = 100; // 2000;

            List <int> startingIndexes = new List <int>();

            for (int i = 0; i < range; i++)
            {
                startingIndexes.Add(289 + i);
            }
            for (int i = 0; i < range; i++)
            {
                startingIndexes.Add(-382 - i);
            }

            List <PendulumSwing> startingSwings = startingIndexes.ConvertAll(
                index => new PendulumSwing(GetPendulumAmplitude(index), 0, null, index, 0));
            Queue <PendulumSwing> queue = new Queue <PendulumSwing>();

            foreach (PendulumSwing swing in startingSwings)
            {
                List <PendulumSwing> successors = swing.GetSuccessors();
                successors.ForEach(successor => queue.Enqueue(successor));
            }

            while (queue.Count > 0)
            {
                PendulumSwing dequeue = queue.Dequeue();

                if (GetPendulumSwingIndexExtended(dequeue.Amplitude) != Double.NaN.ToString())
                {
                    continue;
                }
                if (dequeue.SecondaryIndex > range)
                {
                    continue;
                }

                string extendedIndex = dequeue.PrimaryIndex + "+" + dequeue.SecondaryIndex;
                _extendedAmplitudeDictionary[dequeue.Amplitude] = extendedIndex;

                List <PendulumSwing> successors = dequeue.GetSuccessors();
                successors.ForEach(successor => queue.Enqueue(successor));
            }
        }