private long FindFirstThatFails()
        {
            var firstThatFails = (long)int.MinValue;
            var rollingList    = new RollingList(Day9Constants.Day9PartOneWindowSize);

            for (var i = 0; i < InputLines.Count(); i++)
            {
                var nextNum = InputLines.ElementAt(i);

                if (DoesNumberFail(i, rollingList, nextNum))
                {
                    firstThatFails = nextNum;
                    break;
                }

                rollingList.AddNewEntry(nextNum);
            }

            if (firstThatFails == (long)int.MinValue)
            {
                throw new Exception("No valid solution");
            }

            return(firstThatFails);
        }
        public void TenItemsAreAddedButOnlyLastFiveWillRemain()
        {
            var list = new RollingList<int>(5) {999, 998, 997, 996, 995, 994, 993, 992, 991, 990};

            Assert.That(list.Count, Is.EqualTo(5));
            Assert.That(list, Is.EquivalentTo(new[] { 994, 993, 992, 991, 990 }));
        }
        public void SingleItemIsAddedToList()
        {
            var list = new RollingList<int>(5) {1};

            Assert.That(list.Count, Is.EqualTo(1));
            Assert.That(list[0], Is.EqualTo(1));
        }
        public void MultipleItemsAreAddedToList()
        {
            var list = new RollingList<int>(5) {3, 2, 1, 0};

            Assert.That(list.Count, Is.EqualTo(4));
            Assert.That(list, Is.EquivalentTo(new[]{3,2,1,0}));
        }
 public AccelerationHandler(int secondsBufferSize, int readingFrequency, float multiplyThreshold, float veryCalmTimeThreshold = 5)
 {
     m_SecondsBufferSize     = secondsBufferSize;
     accelerationBuffer      = new RollingList <float>(secondsBufferSize * readingFrequency);
     m_ReadingFrequency      = readingFrequency;
     m_MultiplyThreshold     = multiplyThreshold >= 1 ? multiplyThreshold : 1;
     m_VeryCalmTimeThreshold = veryCalmTimeThreshold;
 }
        public void TwoItemsAreAddedToList()
        {
            var list = new RollingList<int>(5) {2, 1};

            Assert.That(list.Count, Is.EqualTo(2));
            Assert.That(list[0], Is.EqualTo(2));
            Assert.That(list[1], Is.EqualTo(1));
        }
Exemple #7
0
        public void TestCompareSortingGaData()
        {
            const int    seed            = 23196;
            const uint   order           = 48;
            const int    stageCount      = 18;
            const int    sorterCount     = 256;
            const int    sortableCount   = 256;
            const double sorterWinRate   = 0.25;
            const double sortableWinRate = 0.75;
            const StageReplacementMode stageReplacementMode = StageReplacementMode.RandomRewire;
            const int  rounds         = 200;
            const uint rollingListCap = 10;

            var randy = Rando.Standard(seed);

            var dsgOld = randy.ToDirectGaSortingData(
                order: order,
                sorterCount: sorterCount,
                sortableCount: sortableCount,
                stageCount: stageCount,
                sorterWinRate: sorterWinRate,
                sortableWinRate: sortableWinRate,
                stageReplacementMode: stageReplacementMode
                );

            var rlSgd = new RollingList <GaSortingData>(rollingListCap);

            for (var i = 0; i < rollingListCap; i++)
            {
                var dsgNew = dsgOld.EvolveSortersDirect(randy);
                rlSgd.Add(dsgNew);
                dsgOld = dsgNew;
            }


            Stopwatch sw = new Stopwatch();

            sw.Start();
            Console.Write($"\n");

            for (var i = 0; i < rounds; i++)
            {
                var dsgNew = dsgOld.EvolveSortersConjSortablesReplace(randy);
                var rl     = rlSgd.Select(sgd => sgd.CompareReport(dsgNew)).ToList();
                foreach (var r in rl)
                {
                    Console.Write($"{r} ");
                }
                Console.Write($"\n");

                dsgOld = dsgNew;
                rlSgd.Add(dsgNew);
            }


            sw.Stop();
            Console.WriteLine("\nElapsed={0}", sw.Elapsed);
        }
        public void TestRollingList()
        {
            var rl = new RollingList <uint>(10);

            for (uint i = 0; i < 20; i++)
            {
                rl.Add(i);
            }

            var res = rl.ToList();
        }
 private static bool DoesNumberFail(int i, RollingList rollingList, long nextNum)
 {
     return(i > Day9Constants.Day9PartOneWindowSize &&
            !rollingList.HasPairThatTotalNum(nextNum));
 }
Exemple #10
0
 // Start is called before the first frame update
 private void OnEnable()
 {
     m_HeartRateResponses      = new RollingList <HeartRateResponse>(bufferSize);
     antReader.onNewHeartBeat -= SaveHeartBeat;
     antReader.onNewHeartBeat += SaveHeartBeat;
 }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of <see cref="RollingLog"/>
 /// </summary>
 /// <param name="logEntriesCount"></param>
 public RollingLog(int logEntriesCount)
 {
     list = new RollingList<LogEntry>(logEntriesCount);
 }