Exemplo n.º 1
0
        /// <summary>
        /// Generates an array of coeffients in which (the smallest odd number at least as large as (NumSymbols / r)) of them are set
        /// </summary>
        /// <param name="symbolId">The symbol ID has no bearing on how coefficients are generated in this implementation</param>
        /// <param name="complexity">The number of operations that had to be performed</param>
        /// <returns></returns>
        public bool[] GenerateCoefficients(long symbolId, ref int complexity)
        {
            // Pick the degree, which is the number of bits set in the coefficients array
            var degree = NumSymbols / _r;

            if (degree % 2 == 0)
            {
                degree++;                 // It's impossible to solve a system of equations if you've only got even numbers of coefficients set in your systems of equations (http://math.stackexchange.com/a/1751691/284627), so let's make the number odd
            }
            complexity++;

            // Set up the coefficients
            var coefficients = new bool[NumSymbols]; complexity += NumSymbols;

            for (var i = 0; i < degree; i++)             // Make sure that (degree) of them are set
            {
                complexity++;
                coefficients[i] = true;
            }
            Permutator <bool> .Permutate(coefficients, _random);           // Mix them up randomly

            complexity += NumSymbols;

            return(coefficients);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates a random set of coefficients. The number of set coefficients is a number drawn from the Robust Soliton Distribution that was initialized in the constructor
        /// </summary>
        /// <param name="symbolId">For Luby Transform, the symbol ID has no bearing on the coefficients</param>
        /// <param name="complexity">The number of operations that had to be performed</param>
        /// <returns></returns>
        public bool[] GenerateCoefficients(long symbolId, ref int complexity)
        {
            // Set up the set of coefficients
            var coefficients = new bool[NumSymbols]; complexity += NumSymbols;
            var degree       = _pmf.Generate();       // This is the number of bits that will be set in the coefficients array. O(log(n))

            complexity += (int)Math.Ceiling(Math.Log(NumSymbols, 2.0));
            for (var i = 0; i < degree; i++)             // O(n)
            {
                complexity++;
                coefficients[i] = true;
            }
            // Mix up the coefficients array
            Permutator <bool> .Permutate(coefficients, _random);           // O(n)

            complexity += NumSymbols;

            return(coefficients);
        }
Exemplo n.º 3
0
        public override object Task2()
        {
            thrusters = new IntCode.Emulator[5];
            for (int i = 0; i < 5; i++)
            {
                thrusters[i] = new IntCode.Emulator(thrusterCode);
            }

            int[] phaseSettings = new int[] { 5, 6, 7, 8, 9 };
            long  maxSignal     = 0;

            foreach (int[] arr in Permutator.Permutate(phaseSettings))
            {
                long sig = RunFeedbackLoop(arr);
                if (sig > maxSignal)
                {
                    maxSignal = sig;
                }
            }
            return(maxSignal);
        }
Exemplo n.º 4
0
        public override object Task1()
        {
            thrusterCode = IntCode.Tools.ParseCode(input[0]);
            IntCode.Emulator ICE       = new IntCode.Emulator(thrusterCode);
            long             maxSignal = 0;

            var response = IntCode.Emulator.ResultTemplate;

            foreach (int[] arr in Permutator.Permutate(new int[] { 0, 1, 2, 3, 4 }))
            {
                response.Item2 = 0;
                foreach (int s in arr)
                {
                    ICE.Reboot();
                    ICE.QueueInput(s, response.Item2);
                    response = ICE.Run();
                }
                if (response.Item2 > maxSignal)
                {
                    maxSignal = response.Item2;
                }
            }
            return(maxSignal);
        }