示例#1
0
        public static int ProblemOne(int[] intcode)
        {
            var maxOutput     = 0;
            var phaseSettings = Enumerable.Range(0, 44444)
                                .Select(i => i.ToString().PadLeft(5, '0'))
                                .Where(i => i.Distinct().Count() == 5)
                                .Where(i => !i.Any(x => (int)char.GetNumericValue(x) > 4))
                                .ToList();

            foreach (var s in phaseSettings)
            {
                var output = 0;

                for (var t = 0; t < 5; t++)
                {
                    var input    = (int)char.GetNumericValue(s[t]);
                    var computer = new IntcodeComputer(intcode, input, output);
                    while (!computer.Complete)
                    {
                        computer.DoNextInst();
                    }
                    output = computer.Output;
                }

                if (output > maxOutput)
                {
                    maxOutput = output;
                }
            }

            return(maxOutput);
        }
示例#2
0
        public static int ProblemOne(int[] intcode, int inp)
        {
            var computer = new IntcodeComputer(intcode, inp);

            while (!computer.Complete)
            {
                computer.DoNextInst();
            }

            return(computer.Output);
        }