Пример #1
0
        public static int Run(int first, int second)
        {
            List <int> numbers = AdventUtils.ReadCommaIntList("Inputs/Day2Input.txt");

            numbers[1] = first;
            numbers[2] = second;

            int currentPoint = 0;

            while (true)
            {
                if (numbers[currentPoint] == 99)
                {
                    return(numbers[0]);
                }

                int instruction = numbers[currentPoint];
                var value1      = numbers[currentPoint + 1];
                var value2      = numbers[currentPoint + 2];
                var position    = numbers[currentPoint + 3];

                if (instruction != 1 && instruction != 2)
                {
                    throw new Exception("Uh Oh");
                }

                numbers[position] = instruction == 1 ? numbers[value1] + numbers[value2] : numbers[value1] * numbers[value2];

                currentPoint += 4;
            }
        }
Пример #2
0
        public static int Run()
        {
            List <int> numbers = AdventUtils.ReadCommaIntList("Inputs/Day5Input.txt");

            int location = 0;

            while (numbers[location] != 99)
            {
                (int, List <(bool, int)>)nextCode = ReadOpCode(numbers, location);
                RunOpCode(nextCode.Item1, nextCode.Item2, numbers, ref location);
            }

            return(0);
        }
Пример #3
0
        static public int Run()
        {
            int maxValue = int.MinValue;

            List <int> instructions = AdventUtils.ReadCommaIntList("Inputs/Day7Input.txt");
            List <int> opCodes      = new List <int>()
            {
                0, 1, 2, 3, 4
            };

            var things = opCodes.Permute();

            foreach (var foo in things)
            {
                var thing = foo.GetEnumerator();
                thing.MoveNext();
                int output1 = IntCode.Run(new List <int>(instructions), new List <int>()
                {
                    thing.Current, 0
                });
                thing.MoveNext();
                int output2 = IntCode.Run(new List <int>(instructions), new List <int>()
                {
                    thing.Current, output1
                });
                thing.MoveNext();

                int output3 = IntCode.Run(new List <int>(instructions), new List <int>()
                {
                    thing.Current, output2
                });
                thing.MoveNext();

                int output4 = IntCode.Run(new List <int>(instructions), new List <int>()
                {
                    thing.Current, output3
                });
                thing.MoveNext();

                int output5 = IntCode.Run(new List <int>(instructions), new List <int>()
                {
                    thing.Current, output4
                });
                maxValue = Math.Max(maxValue, output5);
            }

            return(maxValue);
        }