Exemple #1
0
        static void Main(string[] args)
        {
            string line =
                "2,380,379,385,1008,2235,768501,381,1005,381,12,99,109,2236,1102,0,1,383,1102,1,0,382,21002,382,1,1,20102,1,383,2,21102,1,37,0,1106,0,578,4,382,4,383,204,1,1001,382,1,382,1007,382,38,381,1005,381,22,1001,383,1,383,1007,383,21,381,1005,381,18,1006,385,69,99,104,-1,104,0,4,386,3,384,1007,384,0,381,1005,381,94,107,0,384,381,1005,381,108,1106,0,161,107,1,392,381,1006,381,161,1101,0,-1,384,1106,0,119,1007,392,36,381,1006,381,161,1101,0,1,384,20101,0,392,1,21102,1,19,2,21101,0,0,3,21102,138,1,0,1106,0,549,1,392,384,392,21002,392,1,1,21101,0,19,2,21101,3,0,3,21102,161,1,0,1106,0,549,1102,1,0,384,20001,388,390,1,21001,389,0,2,21101,180,0,0,1106,0,578,1206,1,213,1208,1,2,381,1006,381,205,20001,388,390,1,21001,389,0,2,21101,0,205,0,1106,0,393,1002,390,-1,390,1102,1,1,384,21002,388,1,1,20001,389,391,2,21101,0,228,0,1106,0,578,1206,1,261,1208,1,2,381,1006,381,253,21002,388,1,1,20001,389,391,2,21102,253,1,0,1106,0,393,1002,391,-1,391,1102,1,1,384,1005,384,161,20001,388,390,1,20001,389,391,2,21101,279,0,0,1105,1,578,1206,1,316,1208,1,2,381,1006,381,304,20001,388,390,1,20001,389,391,2,21101,0,304,0,1105,1,393,1002,390,-1,390,1002,391,-1,391,1102,1,1,384,1005,384,161,20102,1,388,1,20102,1,389,2,21101,0,0,3,21102,338,1,0,1105,1,549,1,388,390,388,1,389,391,389,21002,388,1,1,21002,389,1,2,21101,0,4,3,21101,0,365,0,1106,0,549,1007,389,20,381,1005,381,75,104,-1,104,0,104,0,99,0,1,0,0,0,0,0,0,320,17,16,1,1,19,109,3,21201,-2,0,1,22101,0,-1,2,21101,0,0,3,21102,414,1,0,1106,0,549,21202,-2,1,1,21201,-1,0,2,21102,1,429,0,1105,1,601,1201,1,0,435,1,386,0,386,104,-1,104,0,4,386,1001,387,-1,387,1005,387,451,99,109,-3,2106,0,0,109,8,22202,-7,-6,-3,22201,-3,-5,-3,21202,-4,64,-2,2207,-3,-2,381,1005,381,492,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,481,21202,-4,8,-2,2207,-3,-2,381,1005,381,518,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,507,2207,-3,-4,381,1005,381,540,21202,-4,-1,-1,22201,-3,-1,-3,2207,-3,-4,381,1006,381,529,22101,0,-3,-7,109,-8,2105,1,0,109,4,1202,-2,38,566,201,-3,566,566,101,639,566,566,1201,-1,0,0,204,-3,204,-2,204,-1,109,-4,2106,0,0,109,3,1202,-1,38,594,201,-2,594,594,101,639,594,594,20102,1,0,-2,109,-3,2106,0,0,109,3,22102,21,-2,1,22201,1,-1,1,21101,0,401,2,21102,1,733,3,21102,798,1,4,21102,1,630,0,1106,0,456,21201,1,1437,-2,109,-3,2105,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,2,2,2,2,2,2,2,2,2,2,2,0,2,0,2,2,2,0,2,2,2,2,2,2,0,2,2,0,2,2,2,2,2,2,0,1,1,0,2,2,0,2,0,2,2,2,2,0,2,2,2,2,2,0,2,0,2,2,0,2,2,2,2,0,0,2,2,2,0,2,0,2,0,1,1,0,0,2,2,2,0,0,2,0,2,2,0,2,2,2,2,0,0,2,0,2,2,2,2,2,2,2,0,2,0,2,2,2,0,2,0,1,1,0,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,0,0,2,0,2,0,2,2,0,2,2,0,2,2,2,2,2,0,2,0,1,1,0,2,0,2,2,0,2,2,2,2,2,2,2,2,2,2,0,0,0,2,2,2,0,2,0,2,2,0,0,2,2,0,2,2,2,0,1,1,0,2,2,2,2,0,2,0,0,2,2,2,0,2,2,2,0,2,0,2,0,0,2,2,2,0,2,2,2,0,0,2,0,2,2,0,1,1,0,0,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,0,2,0,2,2,2,0,2,2,2,0,0,1,1,0,2,2,0,2,0,0,2,2,2,0,0,0,2,0,2,2,2,0,2,2,0,2,2,2,2,2,2,2,0,0,0,2,0,0,0,1,1,0,0,2,2,0,0,2,2,2,2,0,2,2,2,0,0,2,0,2,2,0,2,2,2,2,2,2,2,2,2,0,0,0,2,2,0,1,1,0,2,0,0,2,2,2,2,2,2,2,0,2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,0,2,0,1,1,0,2,2,0,2,2,2,0,2,2,0,2,0,2,0,0,0,0,2,2,2,2,2,2,2,2,2,2,0,0,2,2,0,2,2,0,1,1,0,2,2,0,2,2,2,2,2,0,2,0,2,2,2,2,2,0,0,2,2,2,2,0,2,2,0,2,2,2,2,0,2,0,2,0,1,1,0,2,2,0,2,0,2,2,2,2,2,2,0,2,2,2,2,2,2,0,2,2,0,2,2,2,0,2,2,2,2,2,2,2,2,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,25,47,80,47,44,8,60,70,40,60,9,9,88,82,66,91,81,11,3,95,72,53,39,7,33,48,69,45,31,75,6,61,77,72,25,57,70,2,92,78,46,43,88,74,45,27,94,73,90,43,68,90,22,64,2,5,3,40,98,62,25,95,74,1,35,2,1,54,76,68,88,75,30,77,35,40,43,49,85,55,53,12,77,94,89,9,55,8,50,82,7,89,21,85,37,48,4,33,1,28,97,62,95,41,14,22,52,24,72,2,25,51,32,55,36,73,84,22,66,69,36,1,57,97,50,21,98,41,36,59,56,6,80,46,2,86,14,67,77,59,77,5,13,97,98,83,83,42,10,62,64,86,97,17,90,37,27,54,40,39,61,38,11,67,40,65,13,6,85,71,9,93,69,9,28,48,7,93,67,95,90,15,29,90,88,8,75,64,36,42,29,92,24,28,19,4,19,60,16,1,97,43,50,13,10,82,30,19,86,32,93,46,32,66,94,91,44,39,57,51,48,41,92,17,97,16,92,41,92,58,31,94,82,68,25,10,32,98,24,77,17,5,82,30,16,40,82,67,14,16,33,3,96,72,90,83,97,4,55,69,8,30,29,2,47,8,47,52,41,2,14,67,7,57,14,4,94,44,47,9,81,54,91,50,85,41,84,45,65,33,66,28,35,98,89,92,57,81,49,89,89,39,11,8,97,77,12,30,33,77,12,46,64,37,2,84,34,11,54,23,33,57,40,27,95,47,3,17,8,43,15,13,13,41,80,62,93,68,45,82,86,17,44,49,51,29,9,92,67,14,81,16,97,5,65,6,85,46,35,19,50,88,51,23,90,35,44,74,33,36,13,20,44,42,71,51,32,60,22,29,13,26,1,64,26,75,86,43,78,4,43,41,52,67,16,20,63,37,60,2,1,53,37,75,55,3,40,66,36,1,69,18,55,33,81,38,1,81,24,80,31,25,79,30,84,83,71,72,11,94,62,6,35,15,9,63,29,27,76,33,62,77,47,12,61,84,13,38,73,11,32,49,87,6,25,57,87,4,35,91,67,19,30,72,59,79,46,64,66,14,21,15,85,25,22,45,87,96,90,28,83,72,29,71,58,14,50,71,48,19,50,78,63,65,3,41,64,82,50,64,74,77,93,21,52,55,24,34,19,61,19,13,44,80,38,53,36,41,96,17,77,9,84,87,79,51,77,35,5,55,82,23,63,20,66,68,23,92,81,10,2,57,97,4,24,44,28,25,56,4,22,61,11,35,60,75,63,96,60,94,3,65,93,63,28,54,21,10,20,12,46,15,84,93,43,83,71,90,52,48,33,47,32,75,22,22,38,8,62,42,30,95,66,15,75,14,73,17,10,94,64,70,29,51,70,14,68,56,60,57,9,84,16,77,37,17,44,37,22,88,60,85,59,61,52,3,21,15,19,23,90,33,47,36,48,44,30,33,16,22,37,93,78,16,43,18,65,18,61,67,71,51,13,33,7,48,40,70,9,66,12,59,49,67,34,23,51,75,48,23,30,47,23,81,21,42,6,66,34,4,67,45,21,90,34,48,47,43,11,3,54,9,10,35,60,78,19,17,68,1,9,26,92,7,86,66,13,12,31,12,71,55,43,78,39,54,70,62,38,93,25,89,83,37,37,2,60,87,84,48,98,43,1,78,86,97,67,41,85,66,17,23,32,9,35,91,4,18,89,71,4,88,66,50,32,92,9,44,10,23,31,17,53,36,46,94,33,93,68,44,85,73,72,14,34,69,66,77,43,93,23,24,14,17,79,27,63,7,44,95,66,55,83,8,90,58,43,768501";
            IntCodeReader reader = new IntCodeReader(line);

            // 0 and default are black, 1 means white
            var map = new Dictionary <(long x, long y), long>();

            Dictionary <int, char> drawings = new Dictionary <int, char>()
            {
                [0] = ' ',
                [1] = '|',
                [2] = '#',
                [3] = '_',
                [4] = 'o'
            };

            long result = 0;

            Func <long> movePaddle = () =>
                                     Math.Sign(map.First(x => x.Value == 4).Key.x - map.First(x => x.Value == 3).Key.x);

            while (true)
            {
                long x = reader.RunIntCode(movePaddle);
                long y = reader.RunIntCode(movePaddle);
                result = reader.RunIntCode(movePaddle);
                if (x == int.MinValue || y == int.MinValue || result == int.MinValue)
                {
                    break;
                }

                map[(x, y)] = result;
Exemple #2
0
        static void Main(string[] args)
        {
            string line = "3,225,1,225,6,6,1100,1,238,225,104,0,1101,86,8,225,1101,82,69,225,101,36,65,224,1001,224,-106,224,4,224,1002,223,8,223,1001,224,5,224,1,223,224,223,102,52,148,224,101,-1144,224,224,4,224,1002,223,8,223,101,1,224,224,1,224,223,223,1102,70,45,225,1002,143,48,224,1001,224,-1344,224,4,224,102,8,223,223,101,7,224,224,1,223,224,223,1101,69,75,225,1001,18,85,224,1001,224,-154,224,4,224,102,8,223,223,101,2,224,224,1,224,223,223,1101,15,59,225,1102,67,42,224,101,-2814,224,224,4,224,1002,223,8,223,101,3,224,224,1,223,224,223,1101,28,63,225,1101,45,22,225,1101,90,16,225,2,152,92,224,1001,224,-1200,224,4,224,102,8,223,223,101,7,224,224,1,223,224,223,1101,45,28,224,1001,224,-73,224,4,224,1002,223,8,223,101,7,224,224,1,224,223,223,1,14,118,224,101,-67,224,224,4,224,1002,223,8,223,1001,224,2,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,7,677,677,224,102,2,223,223,1005,224,329,1001,223,1,223,1008,226,226,224,1002,223,2,223,1005,224,344,1001,223,1,223,1107,677,226,224,1002,223,2,223,1006,224,359,1001,223,1,223,107,677,677,224,102,2,223,223,1005,224,374,101,1,223,223,1108,677,226,224,102,2,223,223,1005,224,389,1001,223,1,223,1007,677,677,224,1002,223,2,223,1005,224,404,101,1,223,223,1008,677,226,224,102,2,223,223,1005,224,419,101,1,223,223,1108,226,677,224,102,2,223,223,1006,224,434,1001,223,1,223,8,677,226,224,1002,223,2,223,1005,224,449,101,1,223,223,1008,677,677,224,1002,223,2,223,1006,224,464,1001,223,1,223,1108,226,226,224,1002,223,2,223,1005,224,479,1001,223,1,223,1007,226,677,224,102,2,223,223,1005,224,494,1001,223,1,223,1007,226,226,224,102,2,223,223,1005,224,509,101,1,223,223,107,677,226,224,1002,223,2,223,1006,224,524,1001,223,1,223,108,677,677,224,102,2,223,223,1006,224,539,101,1,223,223,7,677,226,224,102,2,223,223,1006,224,554,1001,223,1,223,1107,226,677,224,102,2,223,223,1005,224,569,101,1,223,223,108,677,226,224,1002,223,2,223,1006,224,584,101,1,223,223,108,226,226,224,102,2,223,223,1006,224,599,1001,223,1,223,1107,226,226,224,102,2,223,223,1006,224,614,1001,223,1,223,8,226,677,224,102,2,223,223,1006,224,629,1001,223,1,223,107,226,226,224,102,2,223,223,1005,224,644,101,1,223,223,8,226,226,224,102,2,223,223,1006,224,659,101,1,223,223,7,226,677,224,102,2,223,223,1005,224,674,101,1,223,223,4,223,99,226";

            IntCodeReader reader = new IntCodeReader(line);

            reader.RunIntCode(() => 0);
        }
Exemple #3
0
        private static long GetResultForPosition(string input, int i, int j)
        {
            IntCodeReader reader     = new IntCodeReader(input);
            int           callNumber = 0;
            Func <long>   method     = () => callNumber++ == 0 ? i : j;
            long          result     = reader.RunIntCode(method);

            return(result);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            string line =
                "3,8,1005,8,350,1106,0,11,0,0,0,104,1,104,0,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,1,10,4,10,102,1,8,29,1006,0,82,1006,0,40,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,1002,8,1,57,1,102,15,10,1,1005,14,10,1006,0,33,3,8,102,-1,8,10,101,1,10,10,4,10,1008,8,0,10,4,10,102,1,8,90,1,1008,14,10,2,3,19,10,1006,0,35,1006,0,21,3,8,102,-1,8,10,1001,10,1,10,4,10,108,1,8,10,4,10,1002,8,1,125,1,1105,11,10,2,1105,9,10,1,4,1,10,2,1,4,10,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,101,0,8,164,1006,0,71,3,8,102,-1,8,10,101,1,10,10,4,10,1008,8,0,10,4,10,1002,8,1,189,1006,0,2,1,5,17,10,1006,0,76,1,1002,7,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,1,8,10,4,10,1001,8,0,224,1,3,5,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,1,8,10,4,10,101,0,8,250,1,1,20,10,1,102,13,10,2,101,18,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,0,8,10,4,10,102,1,8,284,2,105,0,10,1,105,20,10,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,1,10,4,10,1002,8,1,315,1006,0,88,1,2,4,10,2,8,17,10,2,6,2,10,101,1,9,9,1007,9,1056,10,1005,10,15,99,109,672,104,0,104,1,21102,1,847069688728,1,21101,0,367,0,1106,0,471,21102,386577216404,1,1,21102,378,1,0,1105,1,471,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,21101,97952923867,0,1,21102,425,1,0,1106,0,471,21101,0,29033143319,1,21102,436,1,0,1105,1,471,3,10,104,0,104,0,3,10,104,0,104,0,21102,1,868410614628,1,21101,0,459,0,1105,1,471,21101,837896909672,0,1,21101,0,470,0,1105,1,471,99,109,2,22102,1,-1,1,21101,40,0,2,21102,502,1,3,21102,492,1,0,1106,0,535,109,-2,2105,1,0,0,1,0,0,1,109,2,3,10,204,-1,1001,497,498,513,4,0,1001,497,1,497,108,4,497,10,1006,10,529,1102,1,0,497,109,-2,2105,1,0,0,109,4,2101,0,-1,534,1207,-3,0,10,1006,10,552,21101,0,0,-3,22101,0,-3,1,22101,0,-2,2,21102,1,1,3,21101,571,0,0,1106,0,576,109,-4,2106,0,0,109,5,1207,-3,1,10,1006,10,599,2207,-4,-2,10,1006,10,599,21202,-4,1,-4,1105,1,667,21202,-4,1,1,21201,-3,-1,2,21202,-2,2,3,21102,1,618,0,1106,0,576,21201,1,0,-4,21101,0,1,-1,2207,-4,-2,10,1006,10,637,21102,0,1,-1,22202,-2,-1,-2,2107,0,-3,10,1006,10,659,21202,-1,1,1,21101,659,0,0,106,0,534,21202,-2,-1,-2,22201,-4,-2,-4,109,-5,2105,1,0";

            IntCodeReader reader = new IntCodeReader(line);

            // 0 and default are black, 1 means white
            var colors = new Dictionary <(int, int), long>();

            // part 2 initialization
            colors[(0, 0)] = 1;
Exemple #5
0
        static void Main(string[] args)
        {
            System.IO.StreamReader file = new System.IO.StreamReader(@"input.txt");
            string input = file.ReadLine();

            IntCodeReader reader = new IntCodeReader(input);

            Dictionary <(int, int), char> map = new Dictionary <(int, int), char>();

            long output = 0;
            int  x      = 0;
            int  y      = 0;
            int  width  = 0;
            int  height = 0;


            // R,R,8,R,12,L,8,L,8,R,12, L,8,R,10, R, 10, L, 7

            string instructions = "B,B,A,C,A,C,A,B,C,B ";

            instructions += "L,10,L,10,R,8 ";
            instructions += "R,8,L,12,R,8 ";
            instructions += "L,12,L,12,L,10,R,10 ";
            instructions += "n ";
            int a = 0;

            Func <long> getInstructions = () =>
            {
                char c = instructions[a];
                a++;
                //Console.WriteLine($"asking for instructions, giving {c} : {(int) c}");
                if (c == ' ')
                {
                    return(10);
                }
                return((int)c);
            };

            bool firstV = true;

            while (output != Int32.MinValue)
            {
                output = reader.RunIntCode(getInstructions);
                int oldX = x;
                int oldY = y;
                switch (output)
                {
                case 35:      // #
                    map[(x, y)] = '#';
Exemple #6
0
        static void Main(string[] args)
        {
            string input =
                "3,8,1001,8,10,8,105,1,0,0,21,42,55,76,89,114,195,276,357,438,99999,3,9,1001,9,3,9,1002,9,3,9,1001,9,3,9,1002,9,2,9,4,9,99,3,9,102,2,9,9,101,5,9,9,4,9,99,3,9,102,3,9,9,101,5,9,9,1002,9,2,9,101,4,9,9,4,9,99,3,9,102,5,9,9,1001,9,3,9,4,9,99,3,9,1001,9,4,9,102,5,9,9,1001,9,5,9,1002,9,2,9,101,2,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,99,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,99";

            // input = "3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54,-5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4,53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10";

            input = "3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5";

            long maxOutput = 0;

            foreach (IEnumerable <int> parameterModes in GetPermutations(new List <int>()
            {
                5, 6, 7, 8, 9
            }, 5))
            {
                int[] parameterModesArray = parameterModes as int[] ?? parameterModes.ToArray();

                IntCodeReader[] readers = new IntCodeReader[]
                {
                    new IntCodeReader(input, parameterModesArray[0]),
                    new IntCodeReader(input, parameterModesArray[1]),
                    new IntCodeReader(input, parameterModesArray[2]),
                    new IntCodeReader(input, parameterModesArray[3]),
                    new IntCodeReader(input, parameterModesArray[4]),
                };

                long currentInput = 0;
                int  i            = 0;
                while (true)
                {
                    long nextInput = readers[i % 5].RunIntCode(() => (int)currentInput);
                    if (nextInput == Int32.MinValue)
                    {
                        break;
                    }
                    currentInput = nextInput;
                    i++;
                }

                if (currentInput > maxOutput)
                {
                    Console.WriteLine($"{currentInput} : {string.Join(',', parameterModesArray)}");
                    Console.WriteLine(i);
                    maxOutput = currentInput;
                }
            }
        }
Exemple #7
0
        static void Main(string[] args)
        {
            System.IO.StreamReader file = new System.IO.StreamReader(@"input.txt");
            string input = file.ReadLine();

            IntCodeReader reader = new IntCodeReader(input);

            // Jump if we have to jump and there is ground in 4 steps
            string instructions = "NOT A J;";

            instructions += "NOT B T;";
            instructions += "OR T J;";
            instructions += "NOT C T;";
            instructions += "OR T J;";
            instructions += "AND D J;";
            // But don't jump if once arrived there is a gap just after and nowhere to land
            // Jump if E or H is true (there is ground)
            instructions += "NOT E T;";
            instructions += "NOT T T;";
            instructions += "OR H T;";
            instructions += "AND T J;";
            instructions += "RUN;";

            int a = 0;

            Func <long> getInstructions = () =>
            {
                char c = instructions[a];
                a++;
                //Console.WriteLine($"asking for instructions, giving {c} : {(int) c}");
                if (c == ';')
                {
                    return(10);
                }
                return((int)c);
            };
            long output = 0;

            while (output != Int32.MinValue)
            {
                output = reader.RunIntCode(getInstructions);
                Console.WriteLine($"{(char)output} : {output}");
                //Console.Write($"{(char)output}");
            }
        }
Exemple #8
0
        static void Main(string[] args)
        {
            string input = "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99";
            //input = "1102,34915192,34915192,7,4,7,99,0";
            //input = "104,1125899906842624,99";
            //input =
            //    "1102,34463338,34463338,63,1007,63,34463338,63,1005,63,53,1101,0,3,1000,109,988,209,12,9,1000,209,6,209,3,203,0,1008,1000,1,63,1005,63,65,1008,1000,2,63,1005,63,904,1008,1000,0,63,1005,63,58,4,25,104,0,99,4,0,104,0,99,4,17,104,0,99,0,0,1102,1,24,1017,1101,0,36,1006,1101,0,30,1011,1101,26,0,1018,1101,32,0,1015,1101,34,0,1004,1101,0,37,1002,1101,25,0,1012,1102,38,1,1010,1101,29,0,1019,1101,308,0,1029,1102,1,696,1027,1102,1,429,1022,1102,1,21,1005,1102,1,33,1013,1101,39,0,1008,1102,20,1,1009,1101,0,652,1025,1102,313,1,1028,1101,0,31,1003,1102,661,1,1024,1101,35,0,1016,1101,0,23,1000,1102,28,1,1014,1102,0,1,1020,1102,27,1,1007,1101,0,1,1021,1102,22,1,1001,1101,703,0,1026,1101,0,422,1023,109,-5,2101,0,9,63,1008,63,31,63,1005,63,205,1001,64,1,64,1105,1,207,4,187,1002,64,2,64,109,6,2102,1,3,63,1008,63,37,63,1005,63,227,1105,1,233,4,213,1001,64,1,64,1002,64,2,64,109,11,21108,40,40,3,1005,1015,255,4,239,1001,64,1,64,1106,0,255,1002,64,2,64,109,-3,21107,41,40,2,1005,1011,275,1001,64,1,64,1105,1,277,4,261,1002,64,2,64,109,4,2107,28,-6,63,1005,63,297,1001,64,1,64,1106,0,299,4,283,1002,64,2,64,109,15,2106,0,0,4,305,1106,0,317,1001,64,1,64,1002,64,2,64,109,-23,2108,22,4,63,1005,63,337,1001,64,1,64,1105,1,339,4,323,1002,64,2,64,109,6,21101,42,0,0,1008,1011,40,63,1005,63,363,1001,64,1,64,1105,1,365,4,345,1002,64,2,64,109,-17,1207,7,21,63,1005,63,381,1105,1,387,4,371,1001,64,1,64,1002,64,2,64,109,14,1201,-1,0,63,1008,63,25,63,1005,63,407,1105,1,413,4,393,1001,64,1,64,1002,64,2,64,109,15,2105,1,0,1001,64,1,64,1105,1,431,4,419,1002,64,2,64,109,-23,2101,0,6,63,1008,63,36,63,1005,63,453,4,437,1106,0,457,1001,64,1,64,1002,64,2,64,109,10,2108,21,-5,63,1005,63,475,4,463,1106,0,479,1001,64,1,64,1002,64,2,64,109,-3,1201,2,0,63,1008,63,20,63,1005,63,505,4,485,1001,64,1,64,1105,1,505,1002,64,2,64,109,4,2107,35,-5,63,1005,63,527,4,511,1001,64,1,64,1105,1,527,1002,64,2,64,109,15,1206,-5,543,1001,64,1,64,1105,1,545,4,533,1002,64,2,64,109,-8,1205,3,563,4,551,1001,64,1,64,1106,0,563,1002,64,2,64,109,-5,1206,7,581,4,569,1001,64,1,64,1105,1,581,1002,64,2,64,109,-8,1207,-3,38,63,1005,63,599,4,587,1105,1,603,1001,64,1,64,1002,64,2,64,109,19,1205,-4,619,1001,64,1,64,1105,1,621,4,609,1002,64,2,64,109,-13,1208,-4,27,63,1005,63,639,4,627,1105,1,643,1001,64,1,64,1002,64,2,64,109,5,2105,1,8,4,649,1001,64,1,64,1106,0,661,1002,64,2,64,109,-16,1202,4,1,63,1008,63,34,63,1005,63,683,4,667,1106,0,687,1001,64,1,64,1002,64,2,64,109,26,2106,0,1,1001,64,1,64,1105,1,705,4,693,1002,64,2,64,109,-9,21102,43,1,-7,1008,1010,46,63,1005,63,725,1105,1,731,4,711,1001,64,1,64,1002,64,2,64,109,-26,1202,9,1,63,1008,63,26,63,1005,63,755,1001,64,1,64,1105,1,757,4,737,1002,64,2,64,109,34,21108,44,43,-8,1005,1017,773,1106,0,779,4,763,1001,64,1,64,1002,64,2,64,109,-15,21102,45,1,1,1008,1011,45,63,1005,63,801,4,785,1106,0,805,1001,64,1,64,1002,64,2,64,109,-14,1208,10,35,63,1005,63,821,1106,0,827,4,811,1001,64,1,64,1002,64,2,64,109,17,2102,1,-4,63,1008,63,20,63,1005,63,853,4,833,1001,64,1,64,1106,0,853,1002,64,2,64,109,6,21107,46,47,-4,1005,1015,871,4,859,1105,1,875,1001,64,1,64,1002,64,2,64,109,-10,21101,47,0,4,1008,1013,47,63,1005,63,901,4,881,1001,64,1,64,1105,1,901,4,64,99,21102,27,1,1,21102,1,915,0,1106,0,922,21201,1,37790,1,204,1,99,109,3,1207,-2,3,63,1005,63,964,21201,-2,-1,1,21102,1,942,0,1106,0,922,22102,1,1,-1,21201,-2,-3,1,21102,957,1,0,1105,1,922,22201,1,-1,-2,1105,1,968,21201,-2,0,-2,109,-3,2105,1,0";

            IntCodeReader intCodeReader = new IntCodeReader(input);

            long res = 0;

            while (res != int.MinValue)
            {
                res = intCodeReader.RunIntCode(() => 1);
                Console.WriteLine(res);
            }
        }