Esempio n. 1
0
        public static int[] Multiply(Intcode intcode, int[] data, Parameter[] parameters)
        {
            int result = parameters[0].GetValue(data) * parameters[1].GetValue(data);

            Intcode.Store(data, result, parameters[2]);
            return(data);
        }
Esempio n. 2
0
        public static int[] StoreInput(Intcode intcode, int[] data, Parameter[] parameters)
        {
            int value = intcode.InputQueue.Dequeue();

            Intcode.Store(data, value, parameters[0]);
            return(data);
        }
Esempio n. 3
0
        public override string Second(string input)
        {
            Day.LogEnabled = false;
            int[] data    = input.GetParts(",").Select(i => int.Parse(i)).ToArray();
            var   intcode = new Intcode();

            return(Solve(data, 19690720));
        }
Esempio n. 4
0
        public override string First(string input)
        {
            Day.LogEnabled = false;
            var intcode = new Intcode();

            intcode.InputQueue.Enqueue(1);
            int[] data = input.GetParts(",").Select(i => int.Parse(i)).ToArray();
            intcode.Execute(data);
            return(intcode.OutputQueue.Last().ToString());
        }
Esempio n. 5
0
 public static int[] JumpIfFalse(Intcode intcode, int[] data, Parameter[] parameters)
 {
     if (parameters[0].GetValue(data) == 0)
     {
         intcode.Ptr = parameters[1].GetValue(data);
     }
     else
     {
         intcode.Ptr += 3;
     }
     return(data);
 }
Esempio n. 6
0
        public override string First(string input)
        {
            // not 337106 too low - read the question, set noun & verb first!
            Day.LogEnabled = false;
            int[] data    = input.GetParts(",").Select(i => int.Parse(i)).ToArray();
            var   intcode = new Intcode()
            {
                Noun = 12, Verb = 2
            };

            return(intcode.Execute(data)[0].ToString());
        }
Esempio n. 7
0
        //public override string FirstTest(string input)
        //{
        //    throw new NotImplementedException("FirstTest");
        //}

        public override string SecondTest(string input)
        {
            Day.ShowInputForOKTest = false;
            Day.LogEnabled         = false;
            var parts     = input.Split(";");
            var inputData = int.Parse(parts[0]);

            input = parts[1];
            var intcode = new Intcode();

            intcode.InputQueue.Enqueue(inputData);
            int[] data = input.GetParts(",").Select(i => int.Parse(i)).ToArray();
            intcode.Execute(data);
            return(intcode.OutputQueue.Last().ToString());
        }
Esempio n. 8
0
//        public override string SecondTest(string input)
//        {
//            throw new NotImplementedException("SecondTest");
//        }

        ////////////////////////////////////////////////////////

        public string Solve(int[] data, int target)
        {
            var intcode = new Intcode();

            for (int verb = 14; verb < 100; verb++)
            {
                intcode.Verb = verb;
                for (int noun = 70; noun < 100; noun++)
                {
                    intcode.Noun = noun;
                    if (intcode.Execute(Intcode.CloneData(data))[0] == target)
                    {
                        return(string.Format("{0}{1}", noun, verb));
                    }
                }
            }
            throw new InvalidOperationException("Huh?");
        }
Esempio n. 9
0
        public override string FirstTest(string input)
        {
            Day.LogEnabled         = false;
            Day.ShowInputForOKTest = false;
            var parts    = input.Split(";");
            var testtype = parts[0];

            input = parts[1];
            if (testtype == "F")
            {
                return(First(input));
            }
            else
            {
                var   intcode = new Intcode();
                int[] data    = input.GetParts(",").Select(i => int.Parse(i)).ToArray();
                return(intcode.Execute(data)[0].ToString());
            }
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            var solved = false;
            var noun   = 0;
            var verb   = 0;

            for (noun = 0; noun <= 99; noun++)
            {
                for (verb = 0; verb <= 99; verb++)
                {
                    var input = new int[] { 1, 0, 0, 3, 1, 1, 2, 3, 1, 3, 4, 3, 1, 5, 0, 3, 2, 6, 1, 19, 2, 19, 13, 23, 1, 23, 10, 27, 1, 13, 27, 31, 2, 31, 10, 35, 1, 35, 9, 39, 1, 39, 13, 43, 1, 13, 43, 47, 1, 47, 13, 51, 1, 13, 51, 55, 1, 5, 55, 59, 2, 10, 59, 63, 1, 9, 63, 67, 1, 6, 67, 71, 2, 71, 13, 75, 2, 75, 13, 79, 1, 79, 9, 83, 2, 83, 10, 87, 1, 9, 87, 91, 1, 6, 91, 95, 1, 95, 10, 99, 1, 99, 13, 103, 1, 13, 103, 107, 2, 13, 107, 111, 1, 111, 9, 115, 2, 115, 10, 119, 1, 119, 5, 123, 1, 123, 2, 127, 1, 127, 5, 0, 99, 2, 14, 0, 0 };

                    input[1] = noun;
                    input[2] = verb;

                    var intCode = new Intcode();
                    var result  = intCode.RunIntCode(input);

                    if (result[0] == desiredResult)
                    {
                        solved = true;
                        break;
                    }
                }
                if (solved)
                {
                    break;
                }
            }

            // Console.WriteLine(solved);
            // Console.WriteLine(noun);
            // Console.WriteLine(verb);


            var x = (100 * noun) + verb;

            Console.WriteLine(x);
        }
Esempio n. 11
0
 public static int[] Equals(Intcode intcode, int[] data, Parameter[] parameters)
 {
     data[parameters[2].GetPositionalAddress()] = (parameters[0].GetValue(data) == parameters[1].GetValue(data)) ? 1 : 0;
     return(data);
 }
Esempio n. 12
0
 public static int[] Halt(Intcode intcode, int[] data, Parameter[] parameters)
 {
     intcode.Halt = true;
     return(data);
 }
Esempio n. 13
0
 public static int[] Output(Intcode intcode, int[] data, Parameter[] parameters)
 {
     intcode.OutputQueue.Enqueue(parameters[0].GetValue(data));
     return(data);
 }