Esempio n. 1
0
 public void Act(IntMachine machine, ReadOnlySpan <long> opData, ReadOnlySpan <byte> modes)
 {
     if (machine.MarshallAccess(opData[0], modes[0]) == 0)
     {
         machine.Jump(machine.MarshallAccess(opData[1], modes[1]));
     }
 }
Esempio n. 2
0
        public override async Task <string> Part2Async(string input)
        {
            var memory       = IntMachine.ParseProgram(input);
            var maxAmplified = await GetMaxAmplifiedValueAsync(memory, new[] { 5, 6, 7, 8, 9 });

            return(maxAmplified.ToString());
        }
Esempio n. 3
0
 public void Act(IntMachine machine, ReadOnlySpan <long> opData, ReadOnlySpan <byte> modes)
 {
     if (machine.MarshallAccess(opData[0], modes[0]) < machine.MarshallAccess(opData[1], modes[1]))
     {
         machine.Write(opData[2], modes[2], 1);
     }
     else
     {
         machine.Write(opData[2], modes[2], 0);
     }
 }
Esempio n. 4
0
        public (int Count, char[, ] Pattern) Solve(Data inputData)
        {
            var data = inputData.OpCodes.Split(',').Select(long.Parse).ToArray();

            var intMachine             = IntMachine.CreateDefault();
            var machineToServerChannel = Channel.CreateUnbounded <long>();
            var serverToMachineChannel = Channel.CreateUnbounded <long>();

            intMachine.InputRequested += (sender, args) =>
            {
                args.ValueAsync = serverToMachineChannel.Reader.ReadAsync();
            };
            intMachine.Output    += (sender, args) => { machineToServerChannel.Writer.WriteAsync(args.Output); };
            intMachine.Completed += (sender, args) => { machineToServerChannel.Writer.Complete(); };

            serverToMachineChannel.Writer.WriteAsync(inputData.StartColor);
            var answerTask = Task.Run(async() =>
            {
                (int X, int Y)position   = (0, 0);
                (int U, int V)forwardVec = (0, 1);
                var paintedCells         = new Dictionary <(int X, int Y), Color>();
                while (await machineToServerChannel.Reader.WaitToReadAsync())
                {
                    var colour = (Color)await machineToServerChannel.Reader.ReadAsync();

                    // Paint the cell!
                    paintedCells[position] = colour;

                    var direction = await machineToServerChannel.Reader.ReadAsync();
                    switch (direction)
                    {
                    case 0:
                        forwardVec = this.RotateVector(forwardVec, 90);
                        break;

                    case 1:
                        forwardVec = this.RotateVector(forwardVec, -90);
                        break;
                    }

                    position = (position.X + forwardVec.U, position.Y + forwardVec.V);
                    await serverToMachineChannel.Writer.WriteAsync(this.GetCellColour(paintedCells, position));
                }

                return(inputData.OutputPaintedValue
                    ? (paintedCells.Count, GetMap(paintedCells))
                    : (paintedCells.Count, (char[, ])null));
            });

            Task.Run(async() => { await intMachine.ProcessAsync(data); });

            return(answerTask.Result);
        }
Esempio n. 5
0
        public int Solve(Data inputData)
        {
            var data       = inputData.OpCodes.Split(',').Select(int.Parse).ToArray();
            var intMachine = IntMachine.CreateDefault();

            var output = 0;

            intMachine.InputRequested += (sender, args) => { args.Value = inputData.InputValue; };
            intMachine.Output         += (sender, args) => { output = (int)args.Output; };

            var state = intMachine.Process(data);

            return(output);
        }
Esempio n. 6
0
        public override async Task <string> Part2Async(string input)
        {
            var intMachine = new IntMachine(input)
            {
                ProgressPublisher = this
            };
            await intMachine.InputChannel.WriteAsync(2);

            await intMachine.RunProgramAsync();

            var result = await intMachine.OutputChannel.ReadAsync();

            return(result.ToString());
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            var program = "3,8,1005,8,339,1106,0,11,0,0,0,104,1,104,0,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,1002,8,1,29,2,1108,11,10,1,1,20,10,2,107,6,10,3,8,102,-1,8,10,101,1,10,10,4,10,108,0,8,10,4,10,101,0,8,62,1006,0,29,1006,0,12,1,1101,5,10,1,2,20,10,3,8,102,-1,8,10,1001,10,1,10,4,10,1008,8,0,10,4,10,1001,8,0,99,1006,0,30,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,0,10,4,10,1001,8,0,124,1006,0,60,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,1,10,4,10,101,0,8,149,2,1007,2,10,1,1105,10,10,3,8,1002,8,-1,10,101,1,10,10,4,10,108,0,8,10,4,10,101,0,8,178,1,1108,15,10,1,1101,5,10,1,109,8,10,1006,0,20,3,8,102,-1,8,10,1001,10,1,10,4,10,108,1,8,10,4,10,101,0,8,215,1006,0,61,1006,0,16,2,1105,15,10,1006,0,50,3,8,1002,8,-1,10,1001,10,1,10,4,10,108,1,8,10,4,10,101,0,8,250,1,1003,10,10,1,9,19,10,2,1004,6,10,2,1106,2,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,1,10,4,10,101,0,8,289,1,1103,13,10,2,105,17,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,108,1,8,10,4,10,1002,8,1,318,101,1,9,9,1007,9,1086,10,1005,10,15,99,109,661,104,0,104,1,21101,0,825599304340,1,21101,356,0,0,1106,0,460,21101,0,937108545948,1,21102,1,367,0,1106,0,460,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,21102,1,21628980315,1,21101,0,414,0,1105,1,460,21101,0,3316673539,1,21101,425,0,0,1106,0,460,3,10,104,0,104,0,3,10,104,0,104,0,21102,988753428840,1,1,21102,1,448,0,1106,0,460,21102,825544569700,1,1,21102,459,1,0,1106,0,460,99,109,2,21202,-1,1,1,21102,1,40,2,21102,491,1,3,21102,481,1,0,1105,1,524,109,-2,2106,0,0,0,1,0,0,1,109,2,3,10,204,-1,1001,486,487,502,4,0,1001,486,1,486,108,4,486,10,1006,10,518,1101,0,0,486,109,-2,2105,1,0,0,109,4,2102,1,-1,523,1207,-3,0,10,1006,10,541,21102,0,1,-3,21201,-3,0,1,22102,1,-2,2,21102,1,1,3,21102,560,1,0,1106,0,565,109,-4,2105,1,0,109,5,1207,-3,1,10,1006,10,588,2207,-4,-2,10,1006,10,588,22101,0,-4,-4,1105,1,656,21202,-4,1,1,21201,-3,-1,2,21202,-2,2,3,21102,1,607,0,1106,0,565,22102,1,1,-4,21101,0,1,-1,2207,-4,-2,10,1006,10,626,21101,0,0,-1,22202,-2,-1,-2,2107,0,-3,10,1006,10,648,21202,-1,1,1,21101,0,648,0,105,1,523,21202,-2,-1,-2,22201,-4,-2,-4,109,-5,2105,1,0";
            var machine = new IntMachine(program);

            var   autoResetEvent = new AutoResetEvent(false);
            Point position       = new Point(0, 0);
            var   isFirstValue   = true;
            int   direction      = 0;
            var   tiles          = new Dictionary <Point, long>();

            tiles.Add(position, 1);
            machine.Input  = () => tiles.TryGetValue(position, out long tmp) ? tmp : 0;
            machine.Output = x =>
            {
                if (isFirstValue)
                {
                    tiles[position] = x;
                }
                else
                {
                    direction = (direction + (x == 0 ? 3 : 1)) % 4;
                    position += GetStepper(direction);
                }
                isFirstValue = !isFirstValue;
            };
            machine.Run();
            Console.WriteLine("Number of painted Tiles = " + tiles.Count);
            Console.WriteLine("X-range = (" + tiles.Keys.Min(x => x.X) + ") - (" + tiles.Keys.Max(x => x.X) + ")");
            Console.WriteLine("Y-range = (" + tiles.Keys.Min(x => x.Y) + ") - (" + tiles.Keys.Max(x => x.Y) + ")");

            for (int y = 0; y <= tiles.Keys.Max(a => a.Y); y++)
            {
                Console.WriteLine();
                for (int x = 0; x <= tiles.Keys.Max(a => a.X); x++)
                {
                    var c = (tiles.TryGetValue(new Point(x, y), out var tmp) ? tmp : 2) switch
                    {
                        0 => ' ',
                        1 => '#',
                        2 => ' ',
                        _ => '?'
                    };
                    Console.Write(c);
                }
            }
        }
Esempio n. 8
0
        private static bool IsInsideBeem(int x, int y)
        {
            bool isFirstCall = true;
            var  machine     = new IntMachine("109,424,203,1,21101,11,0,0,1106,0,282,21102,18,1,0,1106,0,259,1201,1,0,221,203,1,21102,31,1,0,1106,0,282,21101,0,38,0,1105,1,259,21002,23,1,2,21202,1,1,3,21102,1,1,1,21102,1,57,0,1105,1,303,2101,0,1,222,21002,221,1,3,21002,221,1,2,21101,0,259,1,21101,0,80,0,1105,1,225,21101,169,0,2,21101,0,91,0,1106,0,303,1202,1,1,223,20101,0,222,4,21101,259,0,3,21102,225,1,2,21102,225,1,1,21101,0,118,0,1106,0,225,20102,1,222,3,21101,94,0,2,21101,0,133,0,1106,0,303,21202,1,-1,1,22001,223,1,1,21102,148,1,0,1105,1,259,2102,1,1,223,21001,221,0,4,21002,222,1,3,21101,0,22,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21101,0,195,0,106,0,108,20207,1,223,2,21002,23,1,1,21102,1,-1,3,21102,214,1,0,1105,1,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,1202,-4,1,249,21201,-3,0,1,21202,-2,1,2,22101,0,-1,3,21101,0,250,0,1106,0,225,21202,1,1,-4,109,-5,2106,0,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2105,1,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,21202,-2,1,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,22101,0,-2,3,21102,343,1,0,1105,1,303,1106,0,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21201,-4,0,1,21101,0,384,0,1105,1,303,1106,0,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,21201,1,0,-4,109,-5,2106,0,0");

            machine.Input = () => { if (isFirstCall)
                                    {
                                        isFirstCall = false; return(x);
                                    }
                                    return(y); };
            long result = 0;

            machine.Output = c =>
            {
                result = c;
            };
            machine.Run();
            Console.WriteLine($"Testing Y: {y}, X: {x} = {result} ");
            return(result == 1);
        }
Esempio n. 9
0
        public string Solve(Data inputData)
        {
            var data       = inputData.OpCodes.Split(',').Select(long.Parse).ToArray();
            var intMachine = IntMachine.CreateDefault();

            var output = new List <long>();

            intMachine.InputRequested += (sender, args) =>
            {
                args.Value = inputData.InputValue;
            };
            intMachine.Output += (sender, args) =>
            {
                output.Add(args.Output);
            };

            intMachine.Process(data);

            return(string.Join(',', output));
        }
Esempio n. 10
0
        private IntMachine CreateIntMachine(Channel <int> inputCommChannel, Channel <int> outputCommChannel, int machineIdx)
        {
            var intMachine = IntMachine.CreateDefault();

            intMachine.InputRequested += (sender, args) =>
            {
                args.ValueAsync = new ValueTask <long>(Task.Run(async() =>
                {
                    var value = await inputCommChannel.Reader.ReadAsync();
                    return((long)value);
                }));
            };
            intMachine.Output += (sender, args) =>
            {
                _ = outputCommChannel.Writer.WriteAsync((int)args.Output);
            };
            intMachine.Completed += (sender, args) =>
            {
                outputCommChannel.Writer.Complete();
            };

            return(intMachine);
        }
Esempio n. 11
0
        public async Task Act(IntMachine machine, long[] opData, byte[] modes)
        {
            var input = await machine.RequestOutputAsync();

            machine.Write(opData[0], modes[0], input);
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            var machine = new IntMachine("3,1033,1008,1033,1,1032,1005,1032,31,1008,1033,2,1032,1005,1032,58,1008,1033,3,1032,1005,1032,81,1008,1033,4,1032,1005,1032,104,99,101,0,1034,1039,1002,1036,1,1041,1001,1035,-1,1040,1008,1038,0,1043,102,-1,1043,1032,1,1037,1032,1042,1105,1,124,1002,1034,1,1039,101,0,1036,1041,1001,1035,1,1040,1008,1038,0,1043,1,1037,1038,1042,1106,0,124,1001,1034,-1,1039,1008,1036,0,1041,101,0,1035,1040,102,1,1038,1043,1001,1037,0,1042,1105,1,124,1001,1034,1,1039,1008,1036,0,1041,1002,1035,1,1040,1001,1038,0,1043,102,1,1037,1042,1006,1039,217,1006,1040,217,1008,1039,40,1032,1005,1032,217,1008,1040,40,1032,1005,1032,217,1008,1039,5,1032,1006,1032,165,1008,1040,7,1032,1006,1032,165,1101,2,0,1044,1106,0,224,2,1041,1043,1032,1006,1032,179,1102,1,1,1044,1105,1,224,1,1041,1043,1032,1006,1032,217,1,1042,1043,1032,1001,1032,-1,1032,1002,1032,39,1032,1,1032,1039,1032,101,-1,1032,1032,101,252,1032,211,1007,0,31,1044,1106,0,224,1101,0,0,1044,1106,0,224,1006,1044,247,1002,1039,1,1034,101,0,1040,1035,1001,1041,0,1036,102,1,1043,1038,1002,1042,1,1037,4,1044,1105,1,0,9,21,83,15,75,17,11,9,80,22,37,23,19,89,6,29,79,24,75,3,39,3,98,13,20,53,24,30,59,26,13,19,63,84,10,2,57,7,22,43,28,72,11,25,67,17,90,6,10,24,93,76,36,21,34,18,19,15,72,53,18,19,82,8,57,40,18,2,48,71,19,46,26,32,69,29,27,42,8,58,25,17,44,39,47,24,54,32,48,6,26,43,91,4,16,47,45,19,73,3,52,43,25,5,22,73,58,12,56,23,44,7,46,96,48,25,8,16,56,20,48,72,28,44,26,14,23,28,61,29,15,69,86,28,97,6,4,77,4,1,37,55,70,69,22,19,23,78,21,41,2,1,48,29,20,30,22,91,36,15,46,16,83,5,95,38,9,42,84,25,45,3,81,38,79,8,1,78,42,25,58,15,29,48,52,19,36,4,27,43,24,62,6,56,60,22,22,48,23,70,8,83,17,13,63,85,25,13,14,85,79,18,13,63,3,48,94,22,73,18,26,40,68,12,25,10,56,90,59,19,68,25,27,20,20,65,1,22,55,20,1,20,88,24,69,65,13,49,8,5,78,77,1,3,93,9,13,34,17,75,28,13,92,66,35,7,98,3,63,78,59,87,2,80,83,56,15,28,96,25,32,3,27,47,5,73,56,9,59,19,16,60,2,21,50,92,44,19,73,64,7,21,39,19,20,20,63,5,12,6,14,34,12,8,48,12,68,33,14,99,9,85,20,76,18,29,99,52,11,5,98,65,83,15,30,97,35,21,96,4,53,44,23,39,25,53,60,78,85,11,7,4,39,23,84,22,29,56,37,88,18,19,84,4,65,86,8,27,66,24,26,19,95,13,19,61,19,42,85,14,19,29,90,22,15,78,18,90,8,24,21,97,86,15,40,21,61,21,49,61,6,88,40,9,2,38,13,85,16,50,55,93,83,16,77,25,27,91,8,95,15,60,70,63,13,24,24,96,30,8,22,27,74,17,14,92,18,49,4,38,9,33,88,12,62,28,35,77,29,59,3,18,45,5,10,42,58,23,78,72,15,79,2,48,47,14,65,24,5,83,41,11,89,4,57,36,19,12,2,40,21,16,44,36,13,69,70,1,11,51,16,68,30,24,83,26,40,14,82,48,10,5,83,1,76,90,15,44,24,10,88,30,24,78,1,54,97,83,27,46,87,5,19,86,19,48,19,9,50,20,69,17,10,80,34,23,24,18,75,19,20,21,73,11,32,5,15,35,2,77,22,53,18,22,86,6,9,37,30,64,28,77,17,28,12,41,62,59,2,92,97,77,14,3,76,85,11,47,14,85,6,53,2,18,52,29,23,54,35,75,5,97,40,6,45,4,75,64,5,13,86,7,84,84,1,38,23,81,72,5,26,97,70,14,40,9,41,63,41,26,80,57,14,69,90,2,28,95,24,21,80,18,26,33,39,29,11,70,73,69,17,79,13,7,73,6,21,11,75,35,10,23,30,78,75,1,1,73,4,62,30,11,21,6,38,8,40,9,56,3,24,92,66,3,86,61,28,40,17,81,74,58,92,19,4,48,34,39,30,14,36,35,73,12,15,60,49,77,13,53,77,12,20,78,18,34,17,36,17,53,64,7,63,26,20,19,94,16,26,84,13,18,60,47,17,11,56,2,48,53,11,8,79,94,22,14,8,95,7,12,21,77,16,44,4,89,70,96,11,81,8,72,5,35,79,45,1,47,10,86,75,82,5,47,5,65,4,50,22,34,12,84,13,62,80,63,23,45,39,36,0,0,21,21,1,10,1,0,0,0,0,0,0");

            Console.SetBufferSize(230, 70);
            //Console.SetWindowSize(230, 70);
            int x = Console.BufferWidth / 2, y = Console.BufferHeight / 2;
            int startX = x, startY = y;
            int nextX = x, nextY = y;
            var direction = 2;
            var visited   = new List <int>();

            machine.Input = () =>
            {
                Console.SetCursorPosition(0, 0);
                switch (direction)
                {
                case 3:
                    nextX--;
                    return(3);

                case 4:
                    nextX++;
                    return(4);

                case 1:
                    nextY--;
                    return(1);

                case 2:
                    nextY++;
                    return(2);

                default:
                    return(0);
                }
                //while (true)
                //{
                //    Console.SetCursorPosition(0, 0);
                //    var key = Console.ReadKey().Key;
                //    switch (key)
                //    {
                //        case ConsoleKey.LeftArrow:
                //            nextX--;
                //            return 3;
                //        case ConsoleKey.RightArrow:
                //            nextX++;
                //            return 4;
                //        case ConsoleKey.UpArrow:
                //            nextY--;
                //            return 1;
                //        case ConsoleKey.DownArrow:
                //            nextY++;
                //            return 2;
                //    }
                //}
            };
            Console.CursorVisible = false;
            Console.SetCursorPosition(x, y);
            Console.Write("D");
            int           foundX = 0;
            int           foundY = 0;
            HashSet <int> tiles  = new HashSet <int>();

            machine.Output = v =>
            {
                Console.SetCursorPosition(0, 0);
                switch (v)
                {
                case 0:
                    Console.SetCursorPosition(nextX, nextY);
                    Console.Write("#");
                    direction = direction switch { 1 => 4, 4 => 2, 2 => 3, 3 => 1 };
                    nextX     = x;
                    nextY     = y;
                    break;

                case 1:
                    goto case 10;

                case 2:
                    foundX = nextX;
                    foundY = nextY;
                    goto case 10;

                case 10:
                    var nextPos = nextX * 1000 + nextY;
                    var pos     = x * 1000 + y;
                    tiles.Add(pos);
                    if (foundX == 0)
                    {
                        if (visited.Contains(nextPos))
                        {
                            visited.Remove(pos);
                        }
                        else
                        {
                            visited.Add(nextPos);
                        }
                    }
                    Console.SetCursorPosition(x, y);
                    Console.Write(x == foundX && y == foundY ? "X" : visited.Contains(pos) ? "." : " ");
                    x = nextX;
                    y = nextY;
                    Console.SetCursorPosition(x, y);
                    Console.Write(x == foundX && y == foundY ? "X" : "D");
                    direction = direction switch { 4 => 1, 2 => 4, 3 => 2, 1 => 3 };
                    if (x == startX && y == startY)
                    {
                        direction = 0;
                    }
                    break;
                }
            };
            machine.Run();
            Console.SetCursorPosition(0, 0);
            Console.WriteLine("Number of steps: " + visited.Count);

            var oxy_tiles = new HashSet <int>();

            oxy_tiles.Add(foundX * 1000 + foundY);
            var minute = 0;

            while (tiles.Any())
            {
                var adjs = oxy_tiles.SelectMany(GetAdjecent).Where(tiles.Remove).ToList();
                foreach (var adj in adjs)
                {
                    Console.SetCursorPosition(adj / 1000, adj % 1000);
                    Console.Write("O");
                    oxy_tiles.Add(adj);
                }
                minute++;
                Console.ReadKey();
            }

            Console.WriteLine("Number of minutes to oxidiced: " + minute);
            Console.ReadKey();
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            // Om int A
            // Om D och inte C
            // OR C J
            // NOT B T
            // AND T J
            // OR A J

            var lines_answer_a = new[] {
                "OR D J",
                "NOT C T",
                "AND T J",
                "NOT A T",
                "OR T J",
                "WALK"
            };

            //// (D AND !C AND H) OR !A OR (!B AND !E)

            //var lines = new[] {
            //    "OR D J",
            //    "NOT C T",
            //    "AND T J",
            //    "AND D J",
            //    "NOT A T",
            //    "OR T J",
            //    "NOT A T",
            //    "AND A T",
            //    "OR B T",
            //    "OR E T",
            //    "NOT T T",
            //    "OR T J",
            //    "RUN"
            //};


            // (D AND !C AND H AND I) OR !A OR (!B AND !E)

            //!(!E && !H) (E || H)

            // !((A & E & I)||(B & F))

            //var lines = new[] {
            //    "OR A T",
            //    "AND B T",
            //    "AND C T",
            //    "AND G T",
            //    "OR A J",
            //    "AND B J",
            //    "AND F J",
            //    "OR T J",
            //    "OR A T",
            //    "AND E T",
            //    "AND I T",
            //    "OR J T",
            //    "NOT T J",
            //    "RUN"
            //};

            // !(A AND B AND C AND D) AND (D AND (H OR (E AND I)))

            var lines = new[] {
                "OR A T",
                "AND B T",
                "AND C T",
                "AND D T",
                "NOT T J",
                "OR E T",
                "AND I T",
                "OR H T",
                "AND D T",
                "AND T J",
                "NOT A T",
                "OR T J",
                "RUN"
            };

            //.................
            //...........@.....
            //.................
            //#####.###..#..###
            //            // D && (H || (E && I)) || !A



            //var lines = new[] {
            //    "OR E J",
            //    "AND I J",
            //    "OR H J",
            //    "AND D J",
            //    "OR E T",
            //    "OR I T",
            //    "NOT T T",
            //    "AND T J",
            //    "NOT A T",
            //    "OR T J",
            //    //"NOT B J",
            //    //"NOT E T",
            //    //"AND T J",
            //    //"NOT C T",
            //    //"AND D T",
            //    //"AND H T",
            //    //"OR T J",
            //    //"NOT A T",
            //    //"OR T J",
            //    "RUN"
            //};

            var input   = string.Concat(lines.Select(x => x + "\n"));
            var i       = 0;
            var machine = new IntMachine("109,2050,21101,0,966,1,21102,13,1,0,1106,0,1378,21102,1,20,0,1106,0,1337,21101,27,0,0,1105,1,1279,1208,1,65,748,1005,748,73,1208,1,79,748,1005,748,110,1208,1,78,748,1005,748,132,1208,1,87,748,1005,748,169,1208,1,82,748,1005,748,239,21102,1041,1,1,21101,0,73,0,1105,1,1421,21101,0,78,1,21101,1041,0,2,21102,1,88,0,1105,1,1301,21102,68,1,1,21102,1041,1,2,21102,1,103,0,1106,0,1301,1102,1,1,750,1106,0,298,21102,1,82,1,21102,1041,1,2,21101,125,0,0,1105,1,1301,1101,2,0,750,1106,0,298,21101,79,0,1,21101,0,1041,2,21102,1,147,0,1106,0,1301,21102,84,1,1,21101,1041,0,2,21102,1,162,0,1105,1,1301,1101,3,0,750,1105,1,298,21101,0,65,1,21101,0,1041,2,21102,1,184,0,1106,0,1301,21101,0,76,1,21101,0,1041,2,21101,199,0,0,1105,1,1301,21101,75,0,1,21102,1041,1,2,21102,1,214,0,1105,1,1301,21102,221,1,0,1106,0,1337,21101,10,0,1,21101,1041,0,2,21101,0,236,0,1105,1,1301,1106,0,553,21102,1,85,1,21102,1041,1,2,21101,254,0,0,1106,0,1301,21101,0,78,1,21102,1,1041,2,21102,269,1,0,1105,1,1301,21102,1,276,0,1106,0,1337,21102,1,10,1,21102,1041,1,2,21101,291,0,0,1106,0,1301,1101,0,1,755,1105,1,553,21101,0,32,1,21101,0,1041,2,21101,313,0,0,1106,0,1301,21102,1,320,0,1106,0,1337,21101,327,0,0,1105,1,1279,1201,1,0,749,21101,0,65,2,21102,1,73,3,21102,1,346,0,1106,0,1889,1206,1,367,1007,749,69,748,1005,748,360,1101,1,0,756,1001,749,-64,751,1106,0,406,1008,749,74,748,1006,748,381,1101,-1,0,751,1105,1,406,1008,749,84,748,1006,748,395,1101,0,-2,751,1106,0,406,21102,1,1100,1,21101,0,406,0,1106,0,1421,21101,0,32,1,21102,1100,1,2,21102,421,1,0,1106,0,1301,21101,428,0,0,1106,0,1337,21101,0,435,0,1105,1,1279,2102,1,1,749,1008,749,74,748,1006,748,453,1101,-1,0,752,1105,1,478,1008,749,84,748,1006,748,467,1101,0,-2,752,1105,1,478,21102,1,1168,1,21101,0,478,0,1105,1,1421,21102,485,1,0,1106,0,1337,21102,10,1,1,21101,1168,0,2,21102,500,1,0,1106,0,1301,1007,920,15,748,1005,748,518,21101,1209,0,1,21101,0,518,0,1106,0,1421,1002,920,3,529,1001,529,921,529,1001,750,0,0,1001,529,1,537,1002,751,1,0,1001,537,1,545,1001,752,0,0,1001,920,1,920,1106,0,13,1005,755,577,1006,756,570,21101,0,1100,1,21101,0,570,0,1106,0,1421,21101,0,987,1,1105,1,581,21101,0,1001,1,21102,588,1,0,1106,0,1378,1102,758,1,594,102,1,0,753,1006,753,654,21002,753,1,1,21101,0,610,0,1106,0,667,21101,0,0,1,21101,0,621,0,1105,1,1463,1205,1,647,21101,0,1015,1,21102,1,635,0,1106,0,1378,21102,1,1,1,21101,0,646,0,1106,0,1463,99,1001,594,1,594,1105,1,592,1006,755,664,1101,0,0,755,1105,1,647,4,754,99,109,2,1101,0,726,757,21201,-1,0,1,21101,0,9,2,21101,697,0,3,21102,1,692,0,1106,0,1913,109,-2,2106,0,0,109,2,1002,757,1,706,2101,0,-1,0,1001,757,1,757,109,-2,2105,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,255,63,159,191,95,127,223,0,46,68,200,234,187,123,126,182,53,62,125,236,61,103,204,168,235,114,77,108,214,42,140,102,245,170,172,70,166,136,107,106,188,115,50,163,78,124,205,139,203,162,190,110,86,183,184,98,39,157,35,99,228,231,254,54,59,158,49,215,238,154,100,109,242,247,199,248,113,58,143,101,181,229,87,142,120,252,202,175,216,198,220,111,218,243,241,56,92,250,76,237,141,213,38,57,167,189,178,197,177,152,222,69,51,85,251,212,233,55,230,94,219,201,84,171,239,93,232,179,137,71,122,249,47,246,196,185,207,173,156,217,119,79,174,169,153,206,121,60,244,43,138,118,117,186,227,221,34,226,253,116,155,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,0,0,0,0,0,0,0,0,0,0,0,20,73,110,112,117,116,32,105,110,115,116,114,117,99,116,105,111,110,115,58,10,13,10,87,97,108,107,105,110,103,46,46,46,10,10,13,10,82,117,110,110,105,110,103,46,46,46,10,10,25,10,68,105,100,110,39,116,32,109,97,107,101,32,105,116,32,97,99,114,111,115,115,58,10,10,58,73,110,118,97,108,105,100,32,111,112,101,114,97,116,105,111,110,59,32,101,120,112,101,99,116,101,100,32,115,111,109,101,116,104,105,110,103,32,108,105,107,101,32,65,78,68,44,32,79,82,44,32,111,114,32,78,79,84,67,73,110,118,97,108,105,100,32,102,105,114,115,116,32,97,114,103,117,109,101,110,116,59,32,101,120,112,101,99,116,101,100,32,115,111,109,101,116,104,105,110,103,32,108,105,107,101,32,65,44,32,66,44,32,67,44,32,68,44,32,74,44,32,111,114,32,84,40,73,110,118,97,108,105,100,32,115,101,99,111,110,100,32,97,114,103,117,109,101,110,116,59,32,101,120,112,101,99,116,101,100,32,74,32,111,114,32,84,52,79,117,116,32,111,102,32,109,101,109,111,114,121,59,32,97,116,32,109,111,115,116,32,49,53,32,105,110,115,116,114,117,99,116,105,111,110,115,32,99,97,110,32,98,101,32,115,116,111,114,101,100,0,109,1,1005,1262,1270,3,1262,20101,0,1262,0,109,-1,2105,1,0,109,1,21102,1288,1,0,1105,1,1263,21001,1262,0,0,1102,0,1,1262,109,-1,2105,1,0,109,5,21101,1310,0,0,1105,1,1279,21201,1,0,-2,22208,-2,-4,-1,1205,-1,1332,22101,0,-3,1,21102,1332,1,0,1105,1,1421,109,-5,2105,1,0,109,2,21102,1,1346,0,1106,0,1263,21208,1,32,-1,1205,-1,1363,21208,1,9,-1,1205,-1,1363,1105,1,1373,21102,1370,1,0,1105,1,1279,1105,1,1339,109,-2,2105,1,0,109,5,2102,1,-4,1386,20102,1,0,-2,22101,1,-4,-4,21101,0,0,-3,22208,-3,-2,-1,1205,-1,1416,2201,-4,-3,1408,4,0,21201,-3,1,-3,1106,0,1396,109,-5,2105,1,0,109,2,104,10,21202,-1,1,1,21102,1,1436,0,1106,0,1378,104,10,99,109,-2,2106,0,0,109,3,20002,594,753,-1,22202,-1,-2,-1,201,-1,754,754,109,-3,2105,1,0,109,10,21101,5,0,-5,21102,1,1,-4,21102,1,0,-3,1206,-9,1555,21102,3,1,-6,21101,0,5,-7,22208,-7,-5,-8,1206,-8,1507,22208,-6,-4,-8,1206,-8,1507,104,64,1105,1,1529,1205,-6,1527,1201,-7,716,1515,21002,0,-11,-8,21201,-8,46,-8,204,-8,1105,1,1529,104,46,21201,-7,1,-7,21207,-7,22,-8,1205,-8,1488,104,10,21201,-6,-1,-6,21207,-6,0,-8,1206,-8,1484,104,10,21207,-4,1,-8,1206,-8,1569,21102,1,0,-9,1105,1,1689,21208,-5,21,-8,1206,-8,1583,21101,1,0,-9,1105,1,1689,1201,-5,716,1589,20102,1,0,-2,21208,-4,1,-1,22202,-2,-1,-1,1205,-2,1613,21201,-5,0,1,21102,1613,1,0,1105,1,1444,1206,-1,1634,22102,1,-5,1,21101,0,1627,0,1106,0,1694,1206,1,1634,21102,2,1,-3,22107,1,-4,-8,22201,-1,-8,-8,1206,-8,1649,21201,-5,1,-5,1206,-3,1663,21201,-3,-1,-3,21201,-4,1,-4,1105,1,1667,21201,-4,-1,-4,21208,-4,0,-1,1201,-5,716,1676,22002,0,-1,-1,1206,-1,1686,21101,1,0,-4,1105,1,1477,109,-10,2106,0,0,109,11,21102,0,1,-6,21101,0,0,-8,21101,0,0,-7,20208,-6,920,-9,1205,-9,1880,21202,-6,3,-9,1201,-9,921,1725,20102,1,0,-5,1001,1725,1,1732,21002,0,1,-4,22102,1,-4,1,21102,1,1,2,21101,9,0,3,21101,0,1754,0,1105,1,1889,1206,1,1772,2201,-10,-4,1766,1001,1766,716,1766,21002,0,1,-3,1106,0,1790,21208,-4,-1,-9,1206,-9,1786,21202,-8,1,-3,1105,1,1790,22102,1,-7,-3,1001,1732,1,1796,20102,1,0,-2,21208,-2,-1,-9,1206,-9,1812,22102,1,-8,-1,1106,0,1816,22101,0,-7,-1,21208,-5,1,-9,1205,-9,1837,21208,-5,2,-9,1205,-9,1844,21208,-3,0,-1,1105,1,1855,22202,-3,-1,-1,1105,1,1855,22201,-3,-1,-1,22107,0,-1,-1,1105,1,1855,21208,-2,-1,-9,1206,-9,1869,22101,0,-1,-8,1106,0,1873,21201,-1,0,-7,21201,-6,1,-6,1105,1,1708,22101,0,-8,-10,109,-11,2105,1,0,109,7,22207,-6,-5,-3,22207,-4,-6,-2,22201,-3,-2,-1,21208,-1,0,-6,109,-7,2105,1,0,0,109,5,1201,-2,0,1912,21207,-4,0,-1,1206,-1,1930,21102,1,0,-4,21201,-4,0,1,22101,0,-3,2,21102,1,1,3,21101,1949,0,0,1105,1,1954,109,-5,2105,1,0,109,6,21207,-4,1,-1,1206,-1,1977,22207,-5,-3,-1,1206,-1,1977,21201,-5,0,-5,1105,1,2045,22101,0,-5,1,21201,-4,-1,2,21202,-3,2,3,21101,1996,0,0,1106,0,1954,22101,0,1,-5,21101,0,1,-2,22207,-5,-3,-1,1206,-1,2015,21102,0,1,-2,22202,-3,-2,-3,22107,0,-4,-1,1206,-1,2037,22101,0,-2,1,21102,2037,1,0,106,0,1912,21202,-3,-1,-3,22201,-5,-3,-5,109,-6,2105,1,0");

            machine.Input  = () => input[i++];
            machine.Output = c => Console.Write(c > 255 ? (Convert.ToString(c)) : ("" + (char)c));
            machine.Run();
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            var  engine  = new IntMachine("2,380,379,385,1008,2751,248387,381,1005,381,12,99,109,2752,1102,1,0,383,1101,0,0,382,21001,382,0,1,20101,0,383,2,21102,1,37,0,1105,1,578,4,382,4,383,204,1,1001,382,1,382,1007,382,44,381,1005,381,22,1001,383,1,383,1007,383,24,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,1105,1,161,107,1,392,381,1006,381,161,1102,-1,1,384,1106,0,119,1007,392,42,381,1006,381,161,1102,1,1,384,21001,392,0,1,21101,0,22,2,21102,1,0,3,21101,0,138,0,1105,1,549,1,392,384,392,20101,0,392,1,21102,22,1,2,21102,3,1,3,21101,0,161,0,1106,0,549,1102,0,1,384,20001,388,390,1,20101,0,389,2,21102,180,1,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,1101,1,0,384,20102,1,388,1,20001,389,391,2,21102,228,1,0,1105,1,578,1206,1,261,1208,1,2,381,1006,381,253,20102,1,388,1,20001,389,391,2,21102,1,253,0,1105,1,393,1002,391,-1,391,1102,1,1,384,1005,384,161,20001,388,390,1,20001,389,391,2,21102,1,279,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,1106,0,393,1002,390,-1,390,1002,391,-1,391,1102,1,1,384,1005,384,161,21002,388,1,1,21002,389,1,2,21102,0,1,3,21101,0,338,0,1106,0,549,1,388,390,388,1,389,391,389,21001,388,0,1,20102,1,389,2,21101,4,0,3,21101,0,365,0,1105,1,549,1007,389,23,381,1005,381,75,104,-1,104,0,104,0,99,0,1,0,0,0,0,0,0,412,20,19,1,1,22,109,3,22102,1,-2,1,22101,0,-1,2,21101,0,0,3,21101,0,414,0,1105,1,549,21201,-2,0,1,21201,-1,0,2,21102,429,1,0,1106,0,601,2101,0,1,435,1,386,0,386,104,-1,104,0,4,386,1001,387,-1,387,1005,387,451,99,109,-3,2105,1,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,21202,-3,1,-7,109,-8,2106,0,0,109,4,1202,-2,44,566,201,-3,566,566,101,639,566,566,2101,0,-1,0,204,-3,204,-2,204,-1,109,-4,2105,1,0,109,3,1202,-1,44,594,201,-2,594,594,101,639,594,594,20102,1,0,-2,109,-3,2105,1,0,109,3,22102,24,-2,1,22201,1,-1,1,21101,0,541,2,21102,695,1,3,21102,1056,1,4,21102,1,630,0,1105,1,456,21201,1,1695,-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,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,0,0,0,0,0,0,1,1,0,0,2,2,2,2,0,0,2,2,2,2,0,2,0,0,2,2,0,2,0,2,0,2,2,0,2,2,0,2,0,2,2,2,2,2,2,2,0,2,2,0,1,1,0,0,2,2,0,2,2,0,2,2,2,2,2,0,2,2,2,0,2,2,0,2,2,2,2,2,0,0,2,2,2,0,0,2,0,0,2,0,0,2,2,0,1,1,0,0,2,2,2,2,2,0,0,0,2,0,2,0,2,2,0,2,0,2,2,0,2,2,0,2,2,0,2,0,2,0,2,2,2,2,0,2,2,2,0,0,1,1,0,0,2,2,2,2,2,2,2,0,2,2,0,0,2,2,0,0,0,0,0,2,0,2,0,0,2,0,2,0,2,0,0,2,2,0,0,0,2,0,0,0,1,1,0,0,0,2,2,0,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,0,2,2,0,0,2,2,2,2,0,0,0,0,0,0,2,2,2,0,1,1,0,0,2,0,0,2,0,2,0,2,0,0,2,2,2,2,0,2,2,0,2,0,0,2,2,0,0,2,2,0,2,2,0,2,0,0,2,2,2,0,2,0,1,1,0,2,2,2,0,0,2,2,2,0,2,2,0,2,0,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,2,0,2,2,0,2,0,2,2,2,2,0,1,1,0,2,0,2,2,0,2,2,2,2,2,2,2,0,2,2,2,0,0,2,2,2,2,0,0,0,2,2,0,2,0,2,2,2,2,0,2,2,2,2,2,0,1,1,0,2,0,0,2,2,2,2,0,2,0,2,2,2,2,2,2,0,0,2,2,2,2,0,2,2,2,0,2,2,2,0,2,2,2,0,2,2,2,0,0,0,1,1,0,0,2,2,2,2,0,0,2,2,2,0,2,2,2,2,2,2,0,2,0,2,0,2,2,2,2,0,2,2,0,2,2,0,2,2,0,0,2,0,0,0,1,1,0,2,0,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,0,2,2,2,0,2,0,0,0,0,0,0,2,2,0,2,0,2,2,0,2,2,2,0,1,1,0,2,2,2,2,0,0,2,2,2,0,2,0,2,2,2,0,2,2,0,0,0,0,2,2,2,2,2,2,0,2,0,0,0,0,2,2,0,0,2,0,0,1,1,0,2,0,2,2,0,2,2,0,0,2,2,0,2,2,0,2,0,0,2,2,2,2,2,0,2,2,0,0,0,2,2,2,0,0,2,2,2,2,0,2,0,1,1,0,2,2,2,2,0,0,2,0,2,0,0,2,2,0,0,0,0,2,2,0,2,2,2,0,2,2,2,0,0,0,2,2,2,0,2,0,0,2,0,2,0,1,1,0,0,0,2,2,2,2,2,2,2,0,0,2,0,0,0,0,0,2,0,2,2,2,0,2,2,0,2,0,0,0,2,2,2,0,2,2,2,2,2,2,0,1,1,0,0,2,2,0,0,2,2,0,2,2,2,2,2,0,2,2,2,2,2,2,0,2,2,2,2,0,2,2,2,2,2,2,2,2,0,0,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,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,4,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,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,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,3,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,0,0,0,0,0,0,1,43,34,19,38,49,68,88,56,54,52,29,1,43,97,67,20,16,38,59,54,42,95,82,45,46,6,37,75,44,45,68,23,64,81,23,20,23,7,16,74,92,42,42,95,63,5,59,5,48,76,2,35,18,58,7,86,31,20,12,37,9,44,81,62,26,39,1,28,2,10,34,9,83,73,16,43,88,47,40,54,29,77,56,97,98,94,62,84,16,88,74,91,41,43,63,88,93,37,54,44,64,64,96,76,70,47,26,97,18,23,87,62,27,64,82,34,28,64,69,9,44,64,27,39,70,9,27,12,9,85,69,96,54,28,47,72,1,87,63,94,3,70,28,95,3,54,82,13,39,18,13,3,73,7,46,98,72,96,31,61,60,6,50,96,32,94,59,34,32,87,70,34,48,19,78,7,94,42,6,40,69,72,44,76,84,60,66,86,74,40,40,86,48,48,58,31,46,96,4,94,51,76,2,39,89,52,58,4,88,26,31,74,5,53,97,81,38,41,93,90,11,8,89,92,39,71,33,64,9,70,6,71,89,66,8,2,48,78,4,22,61,25,51,79,62,97,87,22,62,95,17,98,50,45,87,41,8,44,75,26,65,3,96,78,10,74,52,55,66,88,10,17,9,15,60,79,6,11,87,36,61,48,36,56,85,95,87,97,67,78,81,69,71,26,65,54,69,89,72,9,83,17,97,59,75,40,90,6,17,69,84,97,69,39,67,49,97,11,37,48,51,97,37,48,41,26,93,82,5,29,63,33,28,55,95,1,9,85,72,52,11,8,77,68,6,56,45,55,59,35,98,24,93,3,82,32,13,79,31,64,45,18,37,4,13,96,24,52,61,94,29,48,17,36,63,22,95,8,75,31,81,49,4,80,78,19,85,15,92,29,31,33,70,60,59,71,25,23,70,23,26,35,60,60,11,20,31,8,37,23,48,93,67,56,95,6,76,41,91,14,63,44,97,67,11,54,40,52,56,49,56,64,33,84,86,14,80,4,69,15,85,83,84,59,68,92,39,25,30,15,45,59,48,12,25,39,59,81,62,31,66,90,41,95,5,60,68,37,92,51,47,89,73,68,40,65,63,87,77,4,74,45,2,79,45,19,50,35,50,51,18,65,21,91,56,20,58,89,18,12,21,59,52,56,69,69,81,12,93,89,43,96,43,27,23,65,64,37,23,17,55,1,20,45,62,2,50,2,67,46,73,32,93,79,8,22,23,87,70,52,42,98,73,94,2,23,14,70,16,86,88,21,11,25,16,14,80,84,17,40,83,17,3,8,16,70,37,76,89,68,34,37,37,48,77,93,17,47,7,77,49,27,48,6,65,84,81,57,96,90,94,31,17,46,59,8,69,92,79,91,14,60,91,49,83,11,65,11,96,90,84,21,40,8,94,8,23,79,20,2,88,42,86,80,4,85,51,34,77,75,78,94,26,83,16,70,45,31,70,96,48,32,76,93,66,9,73,63,42,84,41,1,19,79,28,81,71,76,26,76,74,35,39,52,18,17,81,23,76,14,94,98,72,67,62,39,54,30,8,24,43,53,69,7,92,65,93,71,58,26,73,52,75,93,8,10,71,87,12,4,56,4,70,72,83,24,55,53,34,89,75,45,95,29,96,4,61,76,3,69,10,36,10,79,41,18,74,94,96,32,39,12,32,6,32,93,69,52,75,76,22,74,45,11,51,22,79,96,71,68,9,72,48,77,11,67,50,56,61,63,74,81,48,31,72,35,59,41,4,85,86,3,23,64,79,10,85,97,67,66,87,41,48,17,70,82,8,95,42,36,30,94,57,94,34,88,95,64,64,17,13,92,9,53,52,53,98,21,87,13,34,83,2,72,74,23,87,61,16,20,28,46,57,82,37,83,74,79,7,15,15,59,28,31,16,6,22,66,41,93,82,71,96,41,32,4,30,50,52,30,17,92,71,10,59,73,91,39,20,19,53,15,24,39,79,34,29,41,91,57,49,39,24,12,79,24,63,66,41,15,54,94,90,37,4,65,82,54,28,46,50,64,22,28,60,58,8,41,68,41,28,2,19,9,2,11,87,76,10,63,45,72,12,84,12,35,50,9,46,28,40,29,80,42,39,80,77,37,6,11,13,24,95,60,65,18,97,86,6,64,67,53,18,40,91,98,48,49,47,31,76,68,74,93,14,45,25,29,68,2,49,53,56,87,9,87,87,64,14,69,7,55,55,63,48,78,86,73,45,31,61,83,93,64,68,22,58,80,10,98,63,11,38,64,82,61,8,61,51,39,5,14,69,65,64,90,61,55,37,41,31,40,64,32,27,15,19,58,33,38,90,39,6,13,14,89,52,84,76,1,96,45,5,61,69,44,43,98,80,1,72,63,23,10,77,57,50,74,93,7,15,37,34,40,88,7,248387");
            var  step    = 0;
            long x       = 0;
            int  blocks  = 0;
            long ballX   = 0;
            long paddleX = 0;

            engine.Output = v =>
            {
                switch (step)
                {
                case 0: x = v; break;

                case 1:
                    if (x != -1)
                    {
                        Console.SetCursorPosition((int)x, (int)v);
                    }
                    break;

                default:
                    if (x == -1)
                    {
                        Console.SetCursorPosition(50, 1);
                        Console.Write($"{v:0000000}");
                    }
                    else
                    {
                        switch (v)
                        {
                        case 0:
                            Console.Write(" ");
                            break;

                        case 1:
                            Console.Write("#");
                            break;

                        case 2:
                            Console.Write("X");
                            break;

                        case 3:
                            paddleX = x;
                            Console.Write("-");
                            break;

                        case 4:
                            ballX = x;
                            Console.Write("o"); break;
                        }
                    }
                    break;
                }
                step = (step + 1) % 3;
            };
            engine.Input = () =>
            {
                return(ballX > paddleX ? 1 : ballX < paddleX ? -1 : 0);
                //var key = Console.ReadKey();
                //return key.Key == ConsoleKey.LeftArrow ? -1 : key.Key == ConsoleKey.RightArrow ? 1 : 0;
            };
            engine.Run();
            Console.Read();
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(228, 60);

            var  machine   = new IntMachine("1,330,331,332,109,4364,1102,1182,1,15,1102,1,1449,24,1001,0,0,570,1006,570,36,1001,571,0,0,1001,570,-1,570,1001,24,1,24,1105,1,18,1008,571,0,571,1001,15,1,15,1008,15,1449,570,1006,570,14,21102,58,1,0,1106,0,786,1006,332,62,99,21102,1,333,1,21101,0,73,0,1106,0,579,1102,1,0,572,1102,0,1,573,3,574,101,1,573,573,1007,574,65,570,1005,570,151,107,67,574,570,1005,570,151,1001,574,-64,574,1002,574,-1,574,1001,572,1,572,1007,572,11,570,1006,570,165,101,1182,572,127,102,1,574,0,3,574,101,1,573,573,1008,574,10,570,1005,570,189,1008,574,44,570,1006,570,158,1105,1,81,21101,340,0,1,1105,1,177,21102,1,477,1,1106,0,177,21102,1,514,1,21102,176,1,0,1105,1,579,99,21102,1,184,0,1106,0,579,4,574,104,10,99,1007,573,22,570,1006,570,165,1001,572,0,1182,21102,1,375,1,21102,1,211,0,1105,1,579,21101,1182,11,1,21101,222,0,0,1105,1,979,21102,388,1,1,21102,233,1,0,1106,0,579,21101,1182,22,1,21102,244,1,0,1106,0,979,21101,0,401,1,21101,255,0,0,1106,0,579,21101,1182,33,1,21102,1,266,0,1106,0,979,21101,414,0,1,21102,277,1,0,1106,0,579,3,575,1008,575,89,570,1008,575,121,575,1,575,570,575,3,574,1008,574,10,570,1006,570,291,104,10,21102,1182,1,1,21102,1,313,0,1106,0,622,1005,575,327,1102,1,1,575,21101,327,0,0,1106,0,786,4,438,99,0,1,1,6,77,97,105,110,58,10,33,10,69,120,112,101,99,116,101,100,32,102,117,110,99,116,105,111,110,32,110,97,109,101,32,98,117,116,32,103,111,116,58,32,0,12,70,117,110,99,116,105,111,110,32,65,58,10,12,70,117,110,99,116,105,111,110,32,66,58,10,12,70,117,110,99,116,105,111,110,32,67,58,10,23,67,111,110,116,105,110,117,111,117,115,32,118,105,100,101,111,32,102,101,101,100,63,10,0,37,10,69,120,112,101,99,116,101,100,32,82,44,32,76,44,32,111,114,32,100,105,115,116,97,110,99,101,32,98,117,116,32,103,111,116,58,32,36,10,69,120,112,101,99,116,101,100,32,99,111,109,109,97,32,111,114,32,110,101,119,108,105,110,101,32,98,117,116,32,103,111,116,58,32,43,10,68,101,102,105,110,105,116,105,111,110,115,32,109,97,121,32,98,101,32,97,116,32,109,111,115,116,32,50,48,32,99,104,97,114,97,99,116,101,114,115,33,10,94,62,118,60,0,1,0,-1,-1,0,1,0,0,0,0,0,0,1,24,0,0,109,4,1202,-3,1,586,21001,0,0,-1,22101,1,-3,-3,21102,1,0,-2,2208,-2,-1,570,1005,570,617,2201,-3,-2,609,4,0,21201,-2,1,-2,1105,1,597,109,-4,2105,1,0,109,5,1201,-4,0,630,20102,1,0,-2,22101,1,-4,-4,21102,1,0,-3,2208,-3,-2,570,1005,570,781,2201,-4,-3,652,21002,0,1,-1,1208,-1,-4,570,1005,570,709,1208,-1,-5,570,1005,570,734,1207,-1,0,570,1005,570,759,1206,-1,774,1001,578,562,684,1,0,576,576,1001,578,566,692,1,0,577,577,21102,702,1,0,1105,1,786,21201,-1,-1,-1,1105,1,676,1001,578,1,578,1008,578,4,570,1006,570,724,1001,578,-4,578,21102,1,731,0,1105,1,786,1106,0,774,1001,578,-1,578,1008,578,-1,570,1006,570,749,1001,578,4,578,21102,1,756,0,1105,1,786,1106,0,774,21202,-1,-11,1,22101,1182,1,1,21101,0,774,0,1105,1,622,21201,-3,1,-3,1106,0,640,109,-5,2106,0,0,109,7,1005,575,802,21001,576,0,-6,21001,577,0,-5,1105,1,814,21102,0,1,-1,21101,0,0,-5,21102,0,1,-6,20208,-6,576,-2,208,-5,577,570,22002,570,-2,-2,21202,-5,55,-3,22201,-6,-3,-3,22101,1449,-3,-3,2102,1,-3,843,1005,0,863,21202,-2,42,-4,22101,46,-4,-4,1206,-2,924,21102,1,1,-1,1105,1,924,1205,-2,873,21101,0,35,-4,1105,1,924,1201,-3,0,878,1008,0,1,570,1006,570,916,1001,374,1,374,1202,-3,1,895,1101,0,2,0,1201,-3,0,902,1001,438,0,438,2202,-6,-5,570,1,570,374,570,1,570,438,438,1001,578,558,922,20101,0,0,-4,1006,575,959,204,-4,22101,1,-6,-6,1208,-6,55,570,1006,570,814,104,10,22101,1,-5,-5,1208,-5,53,570,1006,570,810,104,10,1206,-1,974,99,1206,-1,974,1101,1,0,575,21102,973,1,0,1105,1,786,99,109,-7,2105,1,0,109,6,21102,0,1,-4,21101,0,0,-3,203,-2,22101,1,-3,-3,21208,-2,82,-1,1205,-1,1030,21208,-2,76,-1,1205,-1,1037,21207,-2,48,-1,1205,-1,1124,22107,57,-2,-1,1205,-1,1124,21201,-2,-48,-2,1106,0,1041,21101,-4,0,-2,1105,1,1041,21101,0,-5,-2,21201,-4,1,-4,21207,-4,11,-1,1206,-1,1138,2201,-5,-4,1059,2101,0,-2,0,203,-2,22101,1,-3,-3,21207,-2,48,-1,1205,-1,1107,22107,57,-2,-1,1205,-1,1107,21201,-2,-48,-2,2201,-5,-4,1090,20102,10,0,-1,22201,-2,-1,-2,2201,-5,-4,1103,1201,-2,0,0,1105,1,1060,21208,-2,10,-1,1205,-1,1162,21208,-2,44,-1,1206,-1,1131,1105,1,989,21102,439,1,1,1105,1,1150,21102,477,1,1,1105,1,1150,21101,514,0,1,21101,1149,0,0,1105,1,579,99,21101,1157,0,0,1106,0,579,204,-2,104,10,99,21207,-3,22,-1,1206,-1,1138,2102,1,-5,1176,1201,-4,0,0,109,-6,2105,1,0,14,11,44,1,54,1,54,1,54,1,54,1,54,1,54,1,46,9,46,1,54,1,54,1,54,1,54,1,54,1,54,1,48,7,48,1,54,1,54,1,54,1,47,8,47,1,6,1,47,1,6,1,47,1,6,1,47,1,6,1,47,1,6,9,39,1,14,1,39,1,14,1,13,9,9,9,14,1,13,1,7,1,9,1,22,1,13,1,7,1,9,1,22,1,13,1,7,1,9,1,22,1,1,9,3,1,7,1,9,1,22,1,1,1,7,1,3,1,7,1,9,1,22,9,1,1,3,11,7,1,24,1,5,1,1,1,11,1,1,1,7,1,24,1,5,1,1,1,11,11,24,1,5,1,1,1,13,1,32,1,1,7,13,1,32,1,1,1,3,1,15,1,32,7,11,7,32,1,15,1,3,1,1,1,32,1,13,7,1,1,32,1,13,1,1,1,5,1,32,1,1,7,5,1,1,1,5,1,32,1,1,1,5,1,5,1,1,1,5,1,32,11,3,1,1,1,5,1,34,1,5,1,1,1,3,1,1,1,5,1,34,1,5,1,1,1,3,9,34,1,5,1,1,1,5,1,40,1,5,9,40,1,7,1,46,9,32");
            int  x         = 0;
            int  y         = 0;
            int  width     = 0;
            int  height    = 0;
            int  start     = 0;
            char direction = ' ';
            int  pos       = 0;
            var  rails     = new List <int>();
            var  answer    = "A,A,C,B,C,B,C,B,C,A\nL,10,L,8,R,8,L,8,R,6\nR,6,R,6,L,8,L,10\nR,6,R,8,R,8\nn\n";
            var  answer_i  = 0;

            machine        = new IntMachine("2,330,331,332,109,4364,1102,1182,1,15,1102,1,1449,24,1001,0,0,570,1006,570,36,1001,571,0,0,1001,570,-1,570,1001,24,1,24,1105,1,18,1008,571,0,571,1001,15,1,15,1008,15,1449,570,1006,570,14,21102,58,1,0,1106,0,786,1006,332,62,99,21102,1,333,1,21101,0,73,0,1106,0,579,1102,1,0,572,1102,0,1,573,3,574,101,1,573,573,1007,574,65,570,1005,570,151,107,67,574,570,1005,570,151,1001,574,-64,574,1002,574,-1,574,1001,572,1,572,1007,572,11,570,1006,570,165,101,1182,572,127,102,1,574,0,3,574,101,1,573,573,1008,574,10,570,1005,570,189,1008,574,44,570,1006,570,158,1105,1,81,21101,340,0,1,1105,1,177,21102,1,477,1,1106,0,177,21102,1,514,1,21102,176,1,0,1105,1,579,99,21102,1,184,0,1106,0,579,4,574,104,10,99,1007,573,22,570,1006,570,165,1001,572,0,1182,21102,1,375,1,21102,1,211,0,1105,1,579,21101,1182,11,1,21101,222,0,0,1105,1,979,21102,388,1,1,21102,233,1,0,1106,0,579,21101,1182,22,1,21102,244,1,0,1106,0,979,21101,0,401,1,21101,255,0,0,1106,0,579,21101,1182,33,1,21102,1,266,0,1106,0,979,21101,414,0,1,21102,277,1,0,1106,0,579,3,575,1008,575,89,570,1008,575,121,575,1,575,570,575,3,574,1008,574,10,570,1006,570,291,104,10,21102,1182,1,1,21102,1,313,0,1106,0,622,1005,575,327,1102,1,1,575,21101,327,0,0,1106,0,786,4,438,99,0,1,1,6,77,97,105,110,58,10,33,10,69,120,112,101,99,116,101,100,32,102,117,110,99,116,105,111,110,32,110,97,109,101,32,98,117,116,32,103,111,116,58,32,0,12,70,117,110,99,116,105,111,110,32,65,58,10,12,70,117,110,99,116,105,111,110,32,66,58,10,12,70,117,110,99,116,105,111,110,32,67,58,10,23,67,111,110,116,105,110,117,111,117,115,32,118,105,100,101,111,32,102,101,101,100,63,10,0,37,10,69,120,112,101,99,116,101,100,32,82,44,32,76,44,32,111,114,32,100,105,115,116,97,110,99,101,32,98,117,116,32,103,111,116,58,32,36,10,69,120,112,101,99,116,101,100,32,99,111,109,109,97,32,111,114,32,110,101,119,108,105,110,101,32,98,117,116,32,103,111,116,58,32,43,10,68,101,102,105,110,105,116,105,111,110,115,32,109,97,121,32,98,101,32,97,116,32,109,111,115,116,32,50,48,32,99,104,97,114,97,99,116,101,114,115,33,10,94,62,118,60,0,1,0,-1,-1,0,1,0,0,0,0,0,0,1,24,0,0,109,4,1202,-3,1,586,21001,0,0,-1,22101,1,-3,-3,21102,1,0,-2,2208,-2,-1,570,1005,570,617,2201,-3,-2,609,4,0,21201,-2,1,-2,1105,1,597,109,-4,2105,1,0,109,5,1201,-4,0,630,20102,1,0,-2,22101,1,-4,-4,21102,1,0,-3,2208,-3,-2,570,1005,570,781,2201,-4,-3,652,21002,0,1,-1,1208,-1,-4,570,1005,570,709,1208,-1,-5,570,1005,570,734,1207,-1,0,570,1005,570,759,1206,-1,774,1001,578,562,684,1,0,576,576,1001,578,566,692,1,0,577,577,21102,702,1,0,1105,1,786,21201,-1,-1,-1,1105,1,676,1001,578,1,578,1008,578,4,570,1006,570,724,1001,578,-4,578,21102,1,731,0,1105,1,786,1106,0,774,1001,578,-1,578,1008,578,-1,570,1006,570,749,1001,578,4,578,21102,1,756,0,1105,1,786,1106,0,774,21202,-1,-11,1,22101,1182,1,1,21101,0,774,0,1105,1,622,21201,-3,1,-3,1106,0,640,109,-5,2106,0,0,109,7,1005,575,802,21001,576,0,-6,21001,577,0,-5,1105,1,814,21102,0,1,-1,21101,0,0,-5,21102,0,1,-6,20208,-6,576,-2,208,-5,577,570,22002,570,-2,-2,21202,-5,55,-3,22201,-6,-3,-3,22101,1449,-3,-3,2102,1,-3,843,1005,0,863,21202,-2,42,-4,22101,46,-4,-4,1206,-2,924,21102,1,1,-1,1105,1,924,1205,-2,873,21101,0,35,-4,1105,1,924,1201,-3,0,878,1008,0,1,570,1006,570,916,1001,374,1,374,1202,-3,1,895,1101,0,2,0,1201,-3,0,902,1001,438,0,438,2202,-6,-5,570,1,570,374,570,1,570,438,438,1001,578,558,922,20101,0,0,-4,1006,575,959,204,-4,22101,1,-6,-6,1208,-6,55,570,1006,570,814,104,10,22101,1,-5,-5,1208,-5,53,570,1006,570,810,104,10,1206,-1,974,99,1206,-1,974,1101,1,0,575,21102,973,1,0,1105,1,786,99,109,-7,2105,1,0,109,6,21102,0,1,-4,21101,0,0,-3,203,-2,22101,1,-3,-3,21208,-2,82,-1,1205,-1,1030,21208,-2,76,-1,1205,-1,1037,21207,-2,48,-1,1205,-1,1124,22107,57,-2,-1,1205,-1,1124,21201,-2,-48,-2,1106,0,1041,21101,-4,0,-2,1105,1,1041,21101,0,-5,-2,21201,-4,1,-4,21207,-4,11,-1,1206,-1,1138,2201,-5,-4,1059,2101,0,-2,0,203,-2,22101,1,-3,-3,21207,-2,48,-1,1205,-1,1107,22107,57,-2,-1,1205,-1,1107,21201,-2,-48,-2,2201,-5,-4,1090,20102,10,0,-1,22201,-2,-1,-2,2201,-5,-4,1103,1201,-2,0,0,1105,1,1060,21208,-2,10,-1,1205,-1,1162,21208,-2,44,-1,1206,-1,1131,1105,1,989,21102,439,1,1,1105,1,1150,21102,477,1,1,1105,1,1150,21101,514,0,1,21101,1149,0,0,1105,1,579,99,21101,1157,0,0,1106,0,579,204,-2,104,10,99,21207,-3,22,-1,1206,-1,1138,2102,1,-5,1176,1201,-4,0,0,109,-6,2105,1,0,14,11,44,1,54,1,54,1,54,1,54,1,54,1,54,1,46,9,46,1,54,1,54,1,54,1,54,1,54,1,54,1,48,7,48,1,54,1,54,1,54,1,47,8,47,1,6,1,47,1,6,1,47,1,6,1,47,1,6,1,47,1,6,9,39,1,14,1,39,1,14,1,13,9,9,9,14,1,13,1,7,1,9,1,22,1,13,1,7,1,9,1,22,1,13,1,7,1,9,1,22,1,1,9,3,1,7,1,9,1,22,1,1,1,7,1,3,1,7,1,9,1,22,9,1,1,3,11,7,1,24,1,5,1,1,1,11,1,1,1,7,1,24,1,5,1,1,1,11,11,24,1,5,1,1,1,13,1,32,1,1,7,13,1,32,1,1,1,3,1,15,1,32,7,11,7,32,1,15,1,3,1,1,1,32,1,13,7,1,1,32,1,13,1,1,1,5,1,32,1,1,7,5,1,1,1,5,1,32,1,1,1,5,1,5,1,1,1,5,1,32,11,3,1,1,1,5,1,34,1,5,1,1,1,3,1,1,1,5,1,34,1,5,1,1,1,3,9,34,1,5,1,1,1,5,1,40,1,5,9,40,1,7,1,46,9,32");
            machine.Input  = () => answer[answer_i++];
            machine.Output = o =>
            {
                Console.WriteLine("Dust: " + o);
            };
            machine.Run();
            return;

            machine.Output = o =>
            {
                var c = (char)o;
                Console.Write(c == '.' ? ' ' : c);
                switch (c)
                {
                case '<':
                case '>':
                case 'v':
                case '^':
                    pos       = y * 1000 + x;
                    start     = pos;
                    direction = c;
                    goto case '#';

                case '#':
                    rails.Add(y * 1000 + x);
                    x++;
                    break;

                case '.':
                    x++;
                    break;

                case '\n':
                    if (x != 0)
                    {
                        width = x;
                    }
                    x = 0;
                    y++;
                    height++;
                    break;
                }
            };
            machine.Run();

            bool isCross(int tile)
            {
                return(rails.Contains(tile + 1) &&
                       rails.Contains(tile - 1) &&
                       rails.Contains(tile + 1000) &&
                       rails.Contains(tile - 1000));
            }

            var crosses = rails.Where(isCross).ToList();

            foreach (var cross in crosses)
            {
                Console.SetCursorPosition(cross % 1000, cross / 1000);
                Console.Write('O');
            }
            //Console.SetCursorPosition(0, height);
            //var sum = crosses.Sum(x => (x / 1000) * (x % 1000));
            //Console.WriteLine("Sum = " + sum);

            bool isRail(int p) => rails.Contains(p);

            int walk(int p, char d) => d switch
            {
                '<' => p - 1, '>' => p + 1, 'v' => p + 1000, '^' => p - 1000, _ => p
            };
            char turnLeft(char d) => d switch
            {
                '>' => '^', '^' => '<', '<' => 'v', 'v' => '>', _ => ' '
            };
            char turnRight(char d) => d switch
            {
                '>' => 'v', '^' => '>', '<' => '^', 'v' => '<', _ => ' '
            };
            bool canWalk(int p, char d) => isRail(walk(p, d));
            bool tryLeft(int p, char d) => canWalk(pos, turnLeft(d));
            bool tryRight(int p, char d) => canWalk(pos, turnRight(d));

            int walkLength = 0;
            var walks      = new List <char>();

            while (true)
            {
                if (canWalk(pos, direction))
                {
                    walkLength++;
                    pos = walk(pos, direction);
                    Console.SetCursorPosition(pos % 1000, pos / 1000);
                    Console.Write('X');
                }
                else
                {
                    walks.Add((char)('0' + walkLength));
                    //Console.WriteLine(walkLength);
                    walkLength = 0;
                    if (tryLeft(pos, direction))
                    {
                        direction = turnLeft(direction);
                        walks.Add('L');
                        //Console.Write("L");
                    }
                    else if (tryRight(pos, direction))
                    {
                        direction = turnRight(direction);
                        walks.Add('R');
                        //Console.Write("R");
                    }
                    else
                    {
                        break;
                    }
                }
            }
            //Console.SetCursorPosition(0, height);
            //Console.WriteLine(string.Join(',', walks));

            var path = string.Concat(walks);

            //Console.WriteLine(path);
            path = path
                   .Replace(":", "22222")
                   .Replace("8", "2222")
                   .Replace("6", "222")
                   .Replace("0", "")
                   .Replace("2", "11");

            var perm = new List <Section>();

            for (int l = 1; l < path.Length; l++)
            {
                for (int i = 0; i + l < path.Length; i++)
                {
                    perm.Add(new Section {
                        Pattern = path.Substring(i, l), Index = i
                    });
                }
            }

            string compress(string input)
            {
                return(input
                       .Replace("1111111111", ":")
                       .Replace("111111111", "9")
                       .Replace("11111111", "8")
                       .Replace("1111111", "7")
                       .Replace("111111", "6")
                       .Replace("11111", "5")
                       .Replace("1111", "4")
                       .Replace("111", "3")
                       .Replace("11", "2"));
            }

            string toLine(string input)
            {
                return(string.Join(",", input.Select(x => x == ':' ? "10" : x.ToString())));
            }

            string decompress(string input)
            {
                return(input
                       .Replace(":", "1111111111")
                       .Replace("10", "1111111111")
                       .Replace("9", "111111111")
                       .Replace("8", "11111111")
                       .Replace("7", "1111111")
                       .Replace("6", "111111")
                       .Replace("5", "11111")
                       .Replace("4", "1111")
                       .Replace("3", "111")
                       .Replace("2", "11")
                       .Replace(",", ""));
            }

            var grouping =
                new[] { new Part {
                            Pattern = "ABC"
                        }, new Part {
                            Pattern = "L1111111111L11111111R11111111L11111111R111111"
                        } }.Concat(
                perm
                .GroupBy(x => x.Pattern)
                .Where(x => toLine(compress(x.Key)).Length <= 20)
                .Where(x => x.Key.Length > 1 && x.Count() > 2)
                //.Where(x => x.Key.Length < 20 && x.Count() < 20)
                .OrderByDescending(x => x.Key.Length)
                .Where(x => path.Contains("L1111111111L11111111R11111111L11111111R111111" + x.Key))
                .Take(50)
                .Select(x => new Part {
                Pattern = x.Key, FoundSections = x.ToList()
            })
                )
            .ToList();

            int selectedA = -1;
            int selectedB = -1;
            int selectedC = -1;

            void drawMenyItem(int index, char prefix, bool selected)
            {
                Console.ForegroundColor = selected ? ConsoleColor.White : ConsoleColor.Cyan;
                Console.SetCursorPosition(60, index);
                Console.Write(new string(' ', 20));
                Console.SetCursorPosition(60, index);
                Console.Write(prefix + " " + toLine(compress(grouping[index].Pattern))); // + ": " + grouping[index]?.FoundSections?.Count());
            };

            int currentSuggestion = 0;

            void drawMeny()
            {
                for (int i = 0; i < grouping.Count; i++)
                {
                    var prefix =
                        i == 30 ? '*'
                        : i == selectedA ? 'A'
                        : i == selectedB ? 'B'
                        : i == selectedC ? 'C'
                        : ' ';
                    drawMenyItem(i, prefix, i == currentSuggestion);
                }
            };



            void drawSuggestion(Part part, string path, string paint = null)
            {
                path = decompress(path);
                if (paint == null)
                {
                    paint = new string('.', path.Length);
                }
                var sections = part.FoundSections ?? new List <Section>();

                pos       = start;
                direction = '^';
                ConsoleColor color;

                try
                {
                    for (int i = 0; i < path.Length; i++)
                    {
                        var isStart = sections.Any(x => x.Index == i);
                        var isEnd   = sections.Any(x => i == x.Index + x.Pattern.Length - 1);
                        var isIn    = sections.Any(x => i >= x.Index && i < x.Index + x.Pattern.Length);

                        var currentChar =
                            isStart && isEnd ? 'B' :
                            isStart ? 'S' :
                            isEnd ? 'E' :
                            isIn ? 'O' : paint[i];

                        color = currentChar switch { 'S' => ConsoleColor.Yellow, 'E' => ConsoleColor.Yellow, 'O' => ConsoleColor.Yellow, _ => ConsoleColor.Gray };

                        switch (path[i])
                        {
                        case 'L':
                            direction = turnLeft(direction);
                            break;

                        case 'R':
                            direction = turnRight(direction);
                            break;

                        default:
                            pos = walk(pos, direction);
                            //color = (sections.Any(x => x.Index == i && i < x.Index + x.Pattern.Length)) ? ConsoleColor.Green : ConsoleColor.White;
                            Console.ForegroundColor = color;
                            Console.SetCursorPosition(pos % 1000, pos / 1000);
                            Console.Write(currentChar);
                            //Console.Write(currentChar == 'E' ? 'O' : currentChar);
                            //pos = walk(pos, direction);
                            //Console.SetCursorPosition(pos % 1000, pos / 1000);
                            //Console.Write(currentChar == 'S' ? 'O' : currentChar);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.SetCursorPosition(0, height);
                    Console.WriteLine(ex.Message);
                }
            }

            void Clear()
            {
                Console.SetCursorPosition(0, 0);
                var line = new string(' ', width);

                for (int i = 0; i < height; i++)
                {
                    Console.WriteLine(line);
                }
            }

            void drawTry()
            {
                var testPath = string.Concat(grouping[0].Pattern.SelectMany(x => x switch
                {
                    'A' => selectedA == -1 ? "" : grouping[selectedA].Pattern,
                    'B' => selectedB == -1 ? "" : grouping[selectedB].Pattern,
                    'C' => selectedC == -1 ? "" : grouping[selectedC].Pattern,
                    _ => ""
                }));

                var testPaint = string.Concat(grouping[0].Pattern.SelectMany(x => x switch
                {
                    'A' => selectedA == -1 ? "" : new string('A', decompress(grouping[selectedA].Pattern).Length),
                    'B' => selectedB == -1 ? "" : new string('B', decompress(grouping[selectedB].Pattern).Length),
                    'C' => selectedC == -1 ? "" : new string('C', decompress(grouping[selectedC].Pattern).Length),
                    _ => ""
                }));
Esempio n. 16
0
 public void Act(IntMachine machine, ReadOnlySpan <long> opData, ReadOnlySpan <byte> mode)
 {
     machine.SignalOutput(machine.MarshallAccess(opData[0], mode[0]));
 }
Esempio n. 17
0
 public void Act(IntMachine machine, ReadOnlySpan <long> opData, ReadOnlySpan <byte> modeIndicators)
 {
     machine.Break();
 }
Esempio n. 18
0
        public int Solve(Data inputData)
        {
            var cts        = new CancellationTokenSource();
            var data       = inputData.OpCodes.Split(',').Select(long.Parse).ToArray();
            var intMachine = IntMachine.CreateDefault();

            var machineToServerChannel = Channel.CreateUnbounded <long>();
            var serverToMachineChannel = Channel.CreateUnbounded <long>();

            intMachine.InputRequested += (sender, args) =>
            {
                args.ValueAsync = serverToMachineChannel.Reader.ReadAsync(cts.Token);
            };
            intMachine.Output += (sender, args) =>
            {
                machineToServerChannel.Writer.WriteAsync(args.Output, cts.Token);
            };
            intMachine.Completed += (sender, args) =>
            {
                machineToServerChannel.Writer.Complete();
                serverToMachineChannel.Writer.Complete();
            };

            var tiles = new Dictionary <(long X, long Y), ExploredTile>();

            (long X, long Y)position = (0, 0);

            AddTile(position, tiles, TileType.Open);
            var state  = inputData.States.Dequeue();
            var result = Task.Run(async() =>
            {
                Queue <Direction> path = null;
                while (!cts.IsCancellationRequested)
                {
                    if (state == DroidState.Explore && (path == null || path.Count <= 0))
                    {
                        var steps = DecideMovement(position, tiles);
                        if (steps != null && steps.Length > 0)
                        {
                            path = new Queue <Direction>(steps);
                        }
                        else
                        {
                            // Exploration done, move to next state
                            state = inputData.States.Dequeue();
                        }
                    }

                    switch (state)
                    {
                    case DroidState.Explore:
                        position = await this.Explore(position, path, serverToMachineChannel,
                                                      machineToServerChannel, tiles, cts.Token);
                        this.VisualisableUpdate?.Invoke(this, new VisualiserUpdateEventArgs(tiles));
                        break;

                    case DroidState.CalculateDistance:
                        var pathToOxygen =
                            PathingUtility.DijkstraSearch((0, 0), t => t.Type == TileType.OxygenSystem, tiles);
                        cts.Cancel();
                        return(pathToOxygen.Length);

                    case DroidState.CalculateOxygenDistributionTime:
                        var disbursementTime = CalculateOxygenDistributionTime(tiles);
                        cts.Cancel();
                        return(disbursementTime);

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                return(0);
            }, cts.Token);

            Task.Run(async() =>
            {
                try
                {
                    await intMachine.ProcessAsync(data, cts.Token);
                }
                catch (OperationCanceledException)
                {
                    // Ignored
                }
            }, cts.Token);

            return(result.Result);
        }
Esempio n. 19
0
        static void Main(string[] args)
        {
            var machine   = new IntMachine("109,4795,21102,3124,1,1,21102,1,13,0,1105,1,1424,21102,166,1,1,21102,24,1,0,1106,0,1234,21101,31,0,0,1105,1,1984,1106,0,13,6,4,3,2,52,51,21,4,28,56,55,3,19,-9,-10,47,89,88,90,90,6,77,73,85,71,1,76,68,63,65,22,-27,70,76,81,87,5,105,105,107,108,95,4,97,92,109,109,5,110,105,110,108,95,4,115,96,109,109,13,-3,59,101,85,92,97,13,84,80,92,78,34,-15,26,-16,46,88,72,79,84,0,72,76,-3,85,74,79,75,-8,64,68,75,57,65,70,64,66,72,8,-41,32,-22,56,77,82,-4,60,76,62,70,-2,74,-11,55,52,68,67,73,56,60,52,-20,44,56,66,-24,48,58,42,49,54,-16,-53,10,0,56,99,96,95,82,94,83,45,-9,23,-13,61,85,88,74,71,82,73,79,73,89,67,65,-4,62,73,70,69,56,68,57,2,-35,24,-14,64,85,90,4,70,67,79,7,83,-2,68,75,-5,78,65,57,75,-10,76,53,76,0,-37,31,-21,57,78,83,-3,64,74,72,0,76,-9,73,58,57,-13,70,57,49,67,-18,54,64,48,55,-23,48,44,56,42,-14,-51,14,-4,74,95,100,14,97,77,86,79,9,92,79,75,5,27,-17,61,82,87,1,68,78,76,4,80,-5,66,58,78,60,-10,73,60,52,70,-15,57,67,51,58,-6,-43,14,-4,74,95,100,14,81,94,90,90,9,92,79,75,5,60,-50,23,42,38,-32,38,39,30,42,47,-38,30,36,28,25,41,38,34,31,18,23,29,19,33,-52,20,29,-55,27,27,27,8,15,-61,22,16,-64,24,13,18,-54,-69,-70,-14,7,12,-74,-8,-11,1,-71,5,-80,-4,-3,3,-15,-84,-85,-109,29,-19,59,80,85,-1,82,62,71,64,-6,77,64,60,-10,62,66,57,59,63,57,67,51,-19,56,58,57,57,-10,-47,44,-34,39,58,54,-16,60,61,57,64,48,56,-23,52,40,60,38,-28,44,53,-31,55,32,55,-35,48,42,41,-39,32,38,42,-42,-44,12,33,38,-48,28,19,25,32,-52,-76,-77,59,-49,13,55,-30,42,51,-33,49,50,32,31,31,39,36,48,-42,24,35,32,34,29,21,35,19,25,37,-53,14,10,26,18,-57,-59,-3,18,23,-63,1,17,3,-67,1,-4,14,-2,6,-73,-8,14,-76,-12,-78,-40,2,4,-13,-82,-106,-107,35,-25,53,74,79,0,74,60,-10,65,53,72,64,52,56,52,50,-19,53,57,62,56,-24,58,54,38,39,40,-29,-31,2,56,35,-34,-58,-59,138,-128,-74,-108,-33,-31,-26,-44,-101,-114,-33,-37,-51,-39,-35,-47,-54,-122,-37,-45,-52,-59,-58,-128,-46,-65,-42,-49,-133,-132,-102,-60,-68,-56,-55,-139,-141,-106,-61,-65,-72,-78,-64,-148,-70,-72,-151,-68,-81,-81,-72,-156,-74,-86,-86,-80,-161,-97,-81,-95,-165,-94,-98,-103,-83,-97,-102,-90,-173,-90,-103,-111,-99,-178,-95,-108,-112,-182,-115,-115,-101,-117,-120,-104,-120,-122,-191,-106,-128,-118,-110,-127,-196,-196,-199,-135,-123,-134,-203,-115,-126,-121,-207,-143,-127,-141,-211,-143,-139,-145,-148,-132,-148,-150,-219,-154,-156,-155,-148,-224,-141,-147,-227,-144,-157,-161,-231,-165,-161,-165,-168,-161,-157,-159,-166,-162,-157,-228,-265,138,-128,-74,-108,-33,-31,-26,-44,-101,-114,-33,-37,-51,-39,-35,-47,-54,-122,-37,-45,-52,-59,-58,-128,-46,-65,-42,-49,-133,-132,-102,-60,-68,-56,-55,-139,-141,-106,-61,-65,-72,-78,-64,-148,-70,-72,-151,-68,-81,-81,-72,-156,-74,-86,-86,-80,-161,-97,-81,-95,-165,-90,-94,-97,-97,-86,-102,-90,-173,-90,-103,-111,-99,-178,-95,-108,-112,-182,-115,-115,-101,-117,-120,-104,-120,-122,-191,-106,-128,-118,-110,-127,-196,-196,-199,-135,-123,-134,-203,-115,-126,-121,-207,-143,-127,-141,-211,-143,-139,-145,-148,-132,-148,-150,-219,-154,-156,-155,-148,-224,-141,-147,-227,-144,-157,-161,-231,-165,-161,-165,-168,-161,-157,-159,-166,-162,-157,-228,-265,263,-253,-199,-233,-158,-156,-151,-169,-226,-239,-158,-162,-176,-164,-160,-172,-179,-247,-162,-170,-177,-184,-183,-253,-171,-190,-167,-174,-258,-257,-227,-183,-197,-187,-175,-182,-193,-184,-268,-202,-191,-194,-192,-197,-205,-191,-207,-276,-278,-222,-201,-196,-282,-206,-219,-196,-286,-207,-206,-210,-223,-222,-223,-225,-280,-293,-296,-232,-220,-231,-300,-212,-223,-218,-304,-236,-228,-223,-239,-227,-310,-227,-240,-244,-314,-248,-237,-250,-243,-239,-247,-237,-308,-345,-273,-260,-248,-243,-263,-329,-252,-252,-248,-260,-267,-266,-253,-337,-249,-260,-255,-259,-342,-260,-267,-280,-270,-271,-348,-281,-268,-272,-279,-285,-342,-355,-280,-278,-279,-284,-277,-361,-282,-278,-274,-275,-290,-298,-300,-369,-300,-292,-290,-373,-309,-375,-299,-298,-301,-310,-302,-297,-370,-383,-302,-316,-321,-311,-315,-299,-321,-308,-392,-306,-322,-330,-312,-397,-326,-334,-317,-401,-330,-338,-324,-325,-337,-329,-339,-341,-398,-411,-347,-335,-346,-415,-334,-352,-350,-346,-341,-338,-422,-334,-345,-340,-344,-427,-345,-357,-357,-351,-432,-365,-361,-353,-367,-370,-354,-363,-351,-427,-464,-441,-397,-373,-434,-447,-376,-380,-374,-375,-373,-452,-454,-398,-377,-372,-458,-376,-388,-382,-377,-387,-396,-465,-400,-398,-468,-404,-404,-395,-403,-473,-390,-396,-476,-406,-409,-395,-480,-408,-404,-483,-418,-396,-486,-403,-399,-409,-417,-413,-421,-493,37,-5,73,71,-8,75,62,58,-12,62,55,74,64,48,50,-19,45,63,-22,61,48,44,-26,50,37,44,48,-31,33,40,48,41,43,30,37,-25,-38,-63,0,0,109,7,21102,0,1,-2,22208,-2,-5,-1,1205,-1,1169,22202,-2,-4,1,22201,1,-6,1,21201,-2,0,2,21102,1162,1,0,2106,0,-3,21201,-2,1,-2,1105,1,1136,109,-7,2105,1,0,109,6,1201,-5,0,1182,20102,1,0,-2,21101,0,0,-3,21201,-5,1,-5,22208,-3,-2,-1,1205,-1,1229,2201,-5,-3,1205,20102,1,0,1,21202,-3,1,2,22102,1,-2,3,21101,0,1222,0,2105,1,-4,21201,-3,1,-3,1106,0,1192,109,-6,2105,1,0,109,2,22101,0,-1,1,21101,0,1256,2,21101,1251,0,0,1106,0,1174,109,-2,2105,1,0,109,5,22201,-4,-3,-1,22201,-2,-1,-1,204,-1,109,-5,2106,0,0,109,3,2101,0,-2,1280,1006,0,1303,104,45,104,32,1201,-1,66,1291,21002,0,1,1,21101,0,1301,0,1106,0,1234,104,10,109,-3,2105,1,0,0,0,109,2,1201,-1,0,1309,1101,0,0,1308,21101,4601,0,1,21102,1,13,2,21102,4,1,3,21101,0,1353,4,21101,1343,0,0,1106,0,1130,21001,1308,0,-1,109,-2,2105,1,0,70,109,3,2101,0,-2,1360,20008,0,1309,-1,1206,-1,1419,1005,1308,1398,1101,0,1,1308,21008,1309,-1,-1,1206,-1,1387,21102,106,1,1,1106,0,1391,21102,92,1,1,21102,1,1398,0,1105,1,1234,104,45,104,32,1201,-2,1,1408,20101,0,0,1,21102,1,1417,0,1105,1,1234,104,10,109,-3,2106,0,0,109,3,2102,1,-2,1128,21102,34,1,1,21101,1441,0,0,1105,1,1234,1001,1128,0,1447,20101,0,0,1,21102,1,1456,0,1106,0,1234,21101,41,0,1,21102,1,1467,0,1105,1,1234,1001,1128,1,1473,20102,1,0,1,21101,1482,0,0,1106,0,1234,21102,1,46,1,21101,1493,0,0,1105,1,1234,21001,1128,3,1,21102,4,1,2,21102,1,1,3,21102,1273,1,4,21101,0,1516,0,1105,1,1130,21002,1128,1,1,21102,1,1527,0,1105,1,1310,1001,1128,2,1532,21001,0,0,-1,1206,-1,1545,21102,1545,1,0,2105,1,-1,109,-3,2105,1,0,109,0,99,109,2,1101,0,0,1550,21102,4601,1,1,21102,1,13,2,21102,1,4,3,21102,1664,1,4,21102,1,1582,0,1105,1,1130,2,2486,1352,1551,1101,0,0,1552,21001,1550,0,1,21101,0,33,2,21102,1,1702,3,21102,1,1609,0,1105,1,2722,21007,1552,0,-1,1205,-1,1630,20107,0,1552,-1,1205,-1,1637,21101,0,1630,0,1106,0,1752,21101,0,548,1,1105,1,1641,21102,687,1,1,21102,1648,1,0,1106,0,1234,21102,1,4457,1,21102,1,1659,0,1106,0,1424,109,-2,2106,0,0,109,4,21202,-2,-1,-2,1201,-3,0,1675,21008,0,-1,-1,1206,-1,1697,1201,-3,2,1687,20101,-27,0,-3,22201,-3,-2,-3,2001,1550,-3,1550,109,-4,2106,0,0,109,5,21008,1552,0,-1,1206,-1,1747,1201,-3,1901,1716,21001,0,0,-2,1205,-4,1736,20207,-2,1551,-1,1205,-1,1747,1102,-1,1,1552,1106,0,1747,22007,1551,-2,-1,1205,-1,1747,1101,0,1,1552,109,-5,2106,0,0,109,1,21102,826,1,1,21101,1765,0,0,1105,1,1234,20102,1,1550,1,21101,1776,0,0,1105,1,2863,21101,1090,0,1,21102,1,1787,0,1106,0,1234,99,1105,1,1787,109,-1,2106,0,0,109,1,21102,1,512,1,21101,1809,0,0,1106,0,1234,99,1105,1,1809,109,-1,2106,0,0,109,1,1102,1,1,1129,109,-1,2105,1,0,109,1,21102,1,377,1,21102,1,1842,0,1105,1,1234,1106,0,1831,109,-1,2105,1,0,109,1,21101,0,407,1,21101,0,1863,0,1106,0,1234,99,1106,0,1863,109,-1,2106,0,0,109,1,21102,1,452,1,21101,0,1885,0,1106,0,1234,99,1105,1,1885,109,-1,2105,1,0,1941,1947,1953,1958,1965,1972,1978,3584,4102,4099,3470,4223,3883,4100,3983,4146,4026,3610,3464,3599,3502,3738,3509,4167,3991,3449,3751,3564,3734,4060,3697,3805,4201,4057,3543,3545,3992,3674,4039,3751,2281,2468,2418,2450,2487,2125,2505,5,95,108,104,104,23,5,96,91,108,108,1,4,101,105,112,3,6,104,104,106,107,94,-1,6,109,104,109,107,94,-1,5,111,91,100,93,23,5,114,95,108,108,1,109,3,21102,1,1993,0,1106,0,2634,1006,1129,2010,21101,0,316,1,21101,2007,0,0,1105,1,1234,1106,0,2076,21101,0,0,-1,1201,-1,1894,2020,20102,1,0,1,21102,0,1,2,21101,0,0,3,21102,2037,1,0,1106,0,2525,1206,1,2054,1201,-1,1934,2050,21102,1,2051,0,105,1,0,1106,0,2076,21201,-1,1,-1,21207,-1,7,-2,1205,-2,2014,21102,177,1,1,21101,0,2076,0,1105,1,1234,109,-3,2105,1,0,109,3,2001,1128,-2,2089,20102,1,0,-1,1205,-1,2108,21102,1,201,1,21102,2105,1,0,1106,0,1234,1105,1,2119,22102,1,-1,1,21102,2119,1,0,1106,0,1424,109,-3,2106,0,0,0,109,1,1101,0,0,2124,21102,4601,1,1,21101,13,0,2,21102,1,4,3,21101,2173,0,4,21101,2154,0,0,1106,0,1130,1005,2124,2168,21102,1,226,1,21102,2168,1,0,1106,0,1234,109,-1,2106,0,0,109,3,1005,2124,2275,1201,-2,0,2183,20008,0,1128,-1,1206,-1,2275,1201,-2,1,2194,21001,0,0,-1,21201,-1,0,1,21102,5,1,2,21102,1,1,3,21102,1,2216,0,1105,1,2525,1206,1,2275,21101,258,0,1,21101,0,2230,0,1105,1,1234,21201,-1,0,1,21101,0,2241,0,1105,1,1234,104,46,104,10,1102,1,1,2124,1201,-2,0,2256,1102,-1,1,0,1201,-2,3,2262,21002,0,1,-1,1206,-1,2275,21101,2275,0,0,2105,1,-1,109,-3,2106,0,0,0,109,1,1101,0,0,2280,21101,4601,0,1,21102,1,13,2,21101,0,4,3,21102,2329,1,4,21101,2310,0,0,1106,0,1130,1005,2280,2324,21101,0,273,1,21102,1,2324,0,1106,0,1234,109,-1,2106,0,0,109,3,1005,2280,2413,1201,-2,0,2339,21008,0,-1,-1,1206,-1,2413,1201,-2,1,2350,21001,0,0,-1,21202,-1,1,1,21102,1,5,2,21102,1,1,3,21102,2372,1,0,1105,1,2525,1206,1,2413,21102,301,1,1,21102,2386,1,0,1105,1,1234,22101,0,-1,1,21101,0,2397,0,1106,0,1234,104,46,104,10,1101,1,0,2280,1201,-2,0,2412,101,0,1128,0,109,-3,2105,1,0,109,1,21102,-1,1,1,21101,2431,0,0,1106,0,1310,1205,1,2445,21102,1,133,1,21102,1,2445,0,1106,0,1234,109,-1,2106,0,0,109,1,21102,3,1,1,21101,2463,0,0,1105,1,2081,109,-1,2105,1,0,109,1,21101,4,0,1,21101,0,2481,0,1106,0,2081,109,-1,2105,1,0,59,109,1,21101,5,0,1,21102,1,2500,0,1106,0,2081,109,-1,2105,1,0,109,1,21102,1,6,1,21101,0,2518,0,1105,1,2081,109,-1,2105,1,0,0,0,109,5,1201,-3,0,2523,1102,1,1,2524,21202,-4,1,1,21101,2585,0,2,21102,1,2550,0,1106,0,1174,1206,-2,2576,2101,0,-4,2558,2001,0,-3,2566,101,3094,2566,2566,21008,0,-1,-1,1205,-1,2576,1101,0,0,2524,20101,0,2524,-4,109,-5,2106,0,0,109,5,22201,-4,-3,-4,22201,-4,-2,-4,21208,-4,10,-1,1206,-1,2606,21101,-1,0,-4,201,-3,2523,2615,1001,2615,3094,2615,21002,0,1,-1,22208,-4,-1,-1,1205,-1,2629,1102,0,1,2524,109,-5,2105,1,0,109,4,21102,1,3094,1,21102,1,30,2,21102,1,1,3,21102,2706,1,4,21102,2659,1,0,1105,1,1130,21101,0,0,-3,203,-2,21208,-2,10,-1,1205,-1,2701,21207,-2,0,-1,1205,-1,2663,21207,-3,29,-1,1206,-1,2663,2101,3094,-3,2693,1202,-2,1,0,21201,-3,1,-3,1106,0,2663,109,-4,2106,0,0,109,2,1201,-1,0,2715,1101,0,-1,0,109,-2,2106,0,0,0,109,5,1202,-2,1,2721,21207,-4,0,-1,1206,-1,2739,21101,0,0,-4,21201,-4,0,1,21201,-3,0,2,21102,1,1,3,21102,1,2758,0,1106,0,2763,109,-5,2105,1,0,109,6,21207,-4,1,-1,1206,-1,2786,22207,-5,-3,-1,1206,-1,2786,21201,-5,0,-5,1105,1,2858,22102,1,-5,1,21201,-4,-1,2,21202,-3,2,3,21101,2805,0,0,1106,0,2763,22102,1,1,-5,21101,1,0,-2,22207,-5,-3,-1,1206,-1,2824,21102,1,0,-2,22202,-3,-2,-3,22107,0,-4,-1,1206,-1,2850,21201,-2,0,1,21201,-4,-1,2,21101,0,2850,0,106,0,2721,21202,-3,-1,-3,22201,-5,-3,-5,109,-6,2105,1,0,109,3,21208,-2,0,-1,1205,-1,2902,21207,-2,0,-1,1205,-1,2882,1106,0,2888,104,45,21202,-2,-1,-2,22102,1,-2,1,21102,1,2899,0,1105,1,2909,1105,1,2904,104,48,109,-3,2106,0,0,109,4,22101,0,-3,1,21102,1,10,2,21101,0,2926,0,1106,0,3010,22102,1,1,-2,21201,2,0,-1,1206,-2,2948,21202,-2,1,1,21102,2948,1,0,1105,1,2909,22101,48,-1,-1,204,-1,109,-4,2105,1,0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,109,8,21102,0,1,-4,21101,0,0,-3,21102,51,1,-2,21201,-2,-1,-2,1201,-2,2959,3033,21001,0,0,-1,21202,-3,2,-3,22207,-7,-1,-5,1205,-5,3059,21201,-3,1,-3,22102,-1,-1,-5,22201,-7,-5,-7,22207,-3,-6,-5,1205,-5,3078,22102,-1,-6,-5,22201,-3,-5,-3,22201,-1,-4,-4,1205,-2,3024,22102,1,-4,-7,21201,-3,0,-6,109,-8,2106,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,3131,3143,0,3464,3252,3389,0,11,61,105,95,94,17,50,97,83,78,79,83,108,-19,2,7,-79,-9,-2,2,-83,-11,-7,-86,-3,-16,-7,-11,-6,-21,-21,-94,-30,-96,-25,-19,-23,-31,-101,-29,-25,-104,-21,-34,-38,-108,-39,-34,-32,-33,-31,-114,-43,-47,-35,-49,-105,-120,-69,-43,-123,-49,-56,-57,-47,-128,-40,-51,-46,-50,-133,-51,-63,-63,-57,-138,-69,-58,-62,-65,-143,-79,-69,-63,-68,-148,-79,-68,-82,-83,-63,-81,-77,-85,-145,-158,-75,-88,-92,-162,-91,-85,-89,-97,-167,-96,-104,-87,-171,-106,-104,-105,-97,-176,-94,-109,-114,-104,-112,-114,-169,3259,3268,0,3698,0,3324,3124,8,72,88,105,104,85,90,87,100,55,29,48,44,63,-20,54,40,-30,34,-32,43,39,49,48,39,31,-39,44,46,31,40,40,44,-46,18,30,19,-50,32,32,12,28,29,17,21,13,-59,24,18,-62,13,15,14,9,-67,-3,7,6,-71,-7,3,-1,0,-7,-63,3331,3354,0,3252,0,4255,3556,22,65,74,90,87,6,41,86,76,88,70,0,44,63,70,74,79,63,71,57,69,57,58,34,39,81,-4,60,74,73,61,56,72,72,-12,71,65,-15,50,52,-18,68,59,61,53,50,54,46,-26,51,51,53,47,34,44,43,55,-21,3396,3408,0,3124,0,0,0,11,72,87,92,87,95,83,84,14,57,77,77,55,34,55,60,-26,56,41,40,-30,38,54,40,34,34,42,30,31,-39,32,28,40,26,-44,34,24,-47,32,33,29,33,27,31,35,25,13,-57,22,20,16,28,15,6,18,-65,2,2,15,4,1,7,-72,14,5,7,-1,-63,3471,3479,0,0,0,3124,0,7,65,89,99,98,108,85,108,76,8,27,27,36,-48,16,32,18,13,-53,18,10,27,-57,8,10,9,17,-62,16,16,19,7,10,5,21,-1,-3,-72,-3,5,7,-76,6,1,-2,-11,3,-10,-10,-6,-14,-59,-87,1,-10,-5,-84,-10,-24,-94,-21,-11,-14,-14,-99,-22,-22,-18,-103,-23,-20,-33,-23,-39,-109,-27,-26,-30,-44,-114,-28,-44,-52,-34,-105,3563,3584,0,0,3324,3625,4166,20,51,84,80,93,8,62,88,70,84,83,75,79,71,-1,33,66,74,79,63,75,40,32,70,77,-11,57,63,69,54,-16,51,61,-19,69,58,63,-23,63,57,39,53,-28,51,52,38,51,36,44,49,47,-37,41,39,-40,43,30,26,-44,26,33,-16,3632,3641,0,3556,0,3961,0,8,64,102,98,100,88,88,85,92,56,27,54,51,42,51,49,39,-31,51,36,35,42,47,-37,46,40,-40,31,23,43,25,-45,30,22,22,35,-50,22,32,-53,25,23,-56,27,14,10,-60,-22,11,2,14,19,-66,-28,14,4,-2,-71,11,-4,10,9,-3,1,-7,-65,3705,3712,0,3833,0,3252,3753,6,59,107,91,88,90,90,40,38,70,68,58,-12,66,56,-15,68,55,51,-19,47,44,44,50,54,44,58,56,-28,54,39,38,45,-33,50,44,-36,35,27,47,29,-41,38,36,43,24,36,-33,3760,3772,0,4116,3698,0,0,11,68,86,102,87,99,102,80,98,92,94,100,60,24,43,39,51,37,-33,31,47,33,-37,27,-39,30,28,45,-43,40,24,30,22,35,18,29,29,17,30,-27,-55,28,15,11,30,-53,21,7,-63,1,11,10,-67,-2,10,6,13,-3,-5,-74,-7,3,10,0,-67,-80,3,-10,-4,1,-14,-14,-73,3840,3852,0,0,3904,3698,0,11,58,98,90,91,95,85,84,96,86,90,82,51,38,59,64,-22,60,45,44,-26,38,-28,58,42,42,52,36,32,44,29,45,30,-39,47,32,42,29,-44,35,30,18,30,34,-50,19,27,29,-54,-4,24,25,15,19,11,7,20,16,9,3,-66,19,-50,-55,3911,3925,0,0,0,4297,3833,13,54,100,86,103,15,63,98,77,93,94,78,90,90,35,49,68,64,-6,59,61,59,73,-11,53,69,55,-15,49,59,58,-19,64,58,57,-23,59,52,39,49,48,-29,40,48,50,-33,55,44,49,-23,3968,3991,0,3625,0,4020,0,22,50,88,92,7,41,77,83,70,81,77,65,83,67,-3,34,74,79,71,76,56,63,67,28,55,82,79,70,72,78,85,9,-4,68,78,0,75,-9,73,73,61,63,62,-15,71,62,64,56,53,57,49,-9,4027,4036,0,3961,0,0,4393,8,59,102,104,103,93,87,97,99,79,5,24,20,-50,26,17,31,11,21,-56,30,7,17,16,22,-62,2,14,3,-66,17,4,0,-70,6,-3,11,-9,1,-76,-7,-2,0,-1,1,-82,-18,-2,-16,-86,-4,-12,-16,-19,-19,-8,-17,-5,-95,-28,-24,-28,-29,-31,-19,-33,-25,-20,-105,-39,-28,-32,-30,-28,-28,-98,-113,-67,-33,-116,-52,-36,-50,-120,-37,-50,-54,-35,-94,4123,4131,0,0,0,3753,0,7,76,108,88,88,97,89,102,34,48,66,69,73,62,62,61,73,3,72,61,77,55,53,-2,-17,34,53,49,68,-15,59,45,-25,39,49,48,-29,39,46,48,51,55,-21,4173,4182,0,0,3556,0,0,8,75,96,89,96,20,53,83,106,72,11,44,38,37,35,37,38,36,-48,17,29,33,20,-53,-4,14,12,-44,-12,20,23,8,6,-63,-14,4,7,11,0,0,-1,11,-72,4,-5,-7,-3,-10,-5,-1,-11,-81,-17,-5,-16,-85,-4,-18,-17,-4,-14,-26,-10,-93,-12,-26,-23,-19,-30,-30,-31,-19,-102,-26,-35,-37,-33,-40,-35,-31,-41,-97,4262,4270,0,3324,0,0,0,7,68,97,107,89,93,89,97,26,43,91,73,85,91,85,72,72,76,68,3,78,-6,63,74,60,59,79,57,0,54,67,57,52,50,-5,4304,4315,0,3904,0,0,0,10,68,86,106,92,89,82,100,88,93,91,77,6,38,18,36,36,33,-25,-52,-2,30,27,9,21,10,10,8,-47,-62,-15,12,4,-1,16,1,-69,13,14,8,7,2,14,-76,0,-9,-14,3,4,0,-14,-7,-16,-8,-3,-5,-89,-20,-9,-13,-16,-94,-25,-23,-27,-14,-10,-100,-18,-18,-38,-22,-22,-106,-23,-29,-109,-28,-42,-45,-48,-38,-42,-50,-35,-53,-35,-51,-107,4400,4408,0,0,4020,4457,0,7,76,108,102,104,86,91,88,48,36,55,51,-19,46,58,66,46,59,-25,48,58,55,55,-30,36,47,45,50,30,37,41,-38,38,39,41,27,-43,22,34,42,22,35,-35,-50,-51,-2,16,13,30,26,26,15,27,9,15,27,-49,4464,4484,0,4393,0,4556,0,19,64,81,78,95,91,81,91,95,5,39,75,71,68,75,79,77,70,74,79,71,2,38,-41,42,29,25,-45,32,22,40,35,-50,31,27,26,23,-43,-56,8,-58,21,22,8,21,20,21,17,3,-54,15,0,8,12,1,11,-1,11,-7,-77,-8,-3,-1,-2,0,-83,3,-12,-10,-11,-88,-3,-21,-9,-19,-23,-5,-95,-7,-18,-13,-17,-100,-28,-34,-34,-26,-21,-33,-23,-19,-95,4563,4588,1553,4457,0,0,0,24,56,89,75,88,87,88,84,70,13,50,67,75,79,68,78,66,78,60,-10,27,64,66,65,67,12,53,97,83,93,105,105,87,91,83,25,24,23,3625,4653,27,1796,3324,4664,8388636,0,3698,4670,16413,0,3833,4684,542,0,3389,4694,65567,0,4020,4714,32,1850,3464,4726,33,1818,3961,4746,34,1872,3556,4754,163,0,4297,4762,134217764,0,4116,4770,37,1829,3904,4784,16777254,0,3252,4789,268435495,0,10,91,104,87,84,98,86,16,95,93,81,5,104,111,109,93,111,13,102,98,96,95,91,14,92,82,11,77,74,92,29,9,95,111,101,89,101,85,102,82,84,19,78,95,95,92,88,86,72,91,89,4,76,69,70,0,66,80,66,61,72,11,98,99,95,102,86,94,15,90,78,98,76,19,84,85,76,88,93,8,76,82,74,71,87,84,80,77,64,69,75,65,79,7,105,96,102,106,100,98,102,7,91,103,108,98,89,89,101,7,90,102,107,91,99,98,84,13,92,96,87,89,93,87,97,81,11,86,88,87,87,4,111,92,104,93,5,104,105,110,107,92");
            var output    = "";
            var state     = "description";
            var doors     = new List <string>();
            var items     = new List <string>();
            var inventory = new List <string>();
            var story     = new List <string>();

            machine.Output = c =>
            {
                if (c == '\n')
                {
                    Console.WriteLine(output);
                    if (output.StartsWith("You take the "))
                    {
                        inventory.Add(output.Trim('.').Substring("You take the ".Length));
                    }

                    if (output.StartsWith("You drop the "))
                    {
                        inventory.Remove(output.Trim('.').Substring("You drop the ".Length));
                    }

                    if (output.Contains("heavier"))
                    {
                        story.Add("Too heavy");
                    }
                    if (output.Contains("lighter"))
                    {
                        story.Add("Too light");
                    }

                    switch (output)
                    {
                    case "Doors here lead:":
                        state = "doors";
                        break;

                    case "Items here:":
                        state = "items";
                        break;

                    case "Command?":
                        state = "description";
                        break;

                    case "":
                        break;

                    default:
                        switch (state)
                        {
                        case "doors":
                            doors.Add(output.Substring(2));
                            break;

                        case "items":
                            items.Add(output.Substring(2));
                            break;
                        }
                        break;
                    }

                    output = "";
                }
                else
                {
                    output += (char)c;
                }
                //Console.Write((char)c);
            };
            var    tries = new List <string>();
            string input = null;

            machine.Input = () =>
            {
                if (input == null)
                {
                    bool retry;
                    if (tries.Any())
                    {
                        input = tries.First();
                        if (input.StartsWith("TEST: "))
                        {
                            story.Add(input);
                            tries.RemoveAt(0);
                            input = tries.First();
                        }
                        tries.RemoveAt(0);
                    }
                    else
                    {
                        do
                        {
                            retry = false;
                            var key = Console.ReadKey(true);
                            if (key.KeyChar >= '0' && key.KeyChar <= '9')
                            {
                                var index = key.KeyChar - '0';
                                index = (index + 10 - 1) % 10;
                                if ((key.Modifiers & ConsoleModifiers.Alt) == ConsoleModifiers.Alt)
                                {
                                    if (index >= inventory.Count)
                                    {
                                        Console.WriteLine($"I only have {inventory.Count} items in inventory");
                                        retry = true;
                                    }
                                    else
                                    {
                                        input = "drop " + inventory[index];
                                    }
                                }
                                else
                                {
                                    if (index >= items.Count)
                                    {
                                        Console.WriteLine($"There is only {items.Count} items in the room");
                                        retry = true;
                                    }
                                    else
                                    {
                                        input = "take " + items[index];
                                    }
                                }
                            }
                            else
                            {
                                switch (key.Key)
                                {
                                case ConsoleKey.UpArrow:
                                    input = "north";
                                    doors.Clear();
                                    items.Clear();
                                    break;

                                case ConsoleKey.RightArrow:
                                    input = "east";
                                    doors.Clear();
                                    items.Clear();
                                    break;

                                case ConsoleKey.DownArrow:
                                    input = "south";
                                    doors.Clear();
                                    items.Clear();
                                    break;

                                case ConsoleKey.LeftArrow:
                                    input = "west";
                                    doors.Clear();
                                    items.Clear();
                                    break;

                                case ConsoleKey.I:
                                    int i = 1;
                                    if (inventory.Any() == false)
                                    {
                                        Console.WriteLine("You have nothing in inventory");
                                    }
                                    foreach (var thing in inventory)
                                    {
                                        Console.WriteLine($"{i++} - {thing}");
                                    }
                                    retry = true;
                                    break;

                                case ConsoleKey.Q:
                                    Environment.Exit(1);
                                    break;

                                case ConsoleKey.X:
                                    tries = ConstructTries(inventory).ToList();
                                    input = tries.First();
                                    tries.RemoveAt(0);
                                    break;

                                case ConsoleKey.S:
                                    foreach (var s in story)
                                    {
                                        Console.WriteLine(s);
                                    }
                                    retry = true;
                                    break;

                                default:
                                    retry = true;
                                    break;
                                }
                            }
                        } while (retry);
                    }
                }
                else
                {
                    if (input.Length == 0)
                    {
                        input = null;
                        return('\n');
                    }
                }

                char o = input[0];
                input = input.Substring(1);
                return(o);
            };

            machine.Run();
        }
Esempio n. 20
0
        void IOp.Act(IntMachine machine, ReadOnlySpan <long> opData, ReadOnlySpan <byte> modes)
        {
            var input = machine.RequestOutput();

            machine.Write(opData[0], modes[0], input);
        }
 public void Act(IntMachine machine, ReadOnlySpan <long> opData, ReadOnlySpan <byte> modes)
 {
     machine.OffsetRelativeBase(machine.MarshallAccess(opData[0], modes[0]));
 }
Esempio n. 22
0
        public (int BlocksRemaining, long Score) Solve(Data inputData)
        {
            var data       = inputData.OpCodes.Split(',').Select(long.Parse).ToArray();
            var intMachine = IntMachine.CreateDefault();

            long score     = 0;
            var  cellTiles = new Dictionary <(long X, long Y), Tile>();
            var  serverToMachineChannel = Channel.CreateUnbounded <long>();
            var  machineToServerChannel = Channel.CreateUnbounded <long>();
            var  cts = new CancellationTokenSource();

            intMachine.InputRequested += (sender, args) =>
            {
                args.ValueAsync = serverToMachineChannel.Reader.ReadAsync(cts.Token);
            };

            intMachine.Output += (sender, args) =>
            {
                machineToServerChannel.Writer.WriteAsync(args.Output, cts.Token);
            };
            intMachine.Completed += (sender, args) =>
            {
                machineToServerChannel.Writer.Complete();
                serverToMachineChannel.Writer.Complete();
                cts.Cancel();
            };

            var ballPosSemaphore = new SemaphoreSlim(0, 1);

            Task.Run(async() =>
            {
                while (!cts.Token.IsCancellationRequested)
                {
                    await ballPosSemaphore.WaitAsync(cts.Token);
                    if (cts.Token.IsCancellationRequested)
                    {
                        return;
                    }

                    while (true)
                    {
                        if (cellTiles.ContainsValue(Tile.Ball) && cellTiles.ContainsValue(Tile.HorizontalPaddle))
                        {
                            KeyValuePair <(long X, long Y), Tile> ballPos;
                            KeyValuePair <(long X, long Y), Tile> paddlePos;
                            lock (cellTiles)
                            {
                                ballPos   = cellTiles.FirstOrDefault(v => v.Value == Tile.Ball);
                                paddlePos = cellTiles.FirstOrDefault(v => v.Value == Tile.HorizontalPaddle);
                            }

                            if (ballPos.Key.X > paddlePos.Key.X)
                            {
                                await serverToMachineChannel.Writer.WriteAsync(1, cts.Token);
                            }
                            else if (ballPos.Key.X < paddlePos.Key.X)
                            {
                                await serverToMachineChannel.Writer.WriteAsync(-1, cts.Token);
                            }
                            else
                            {
                                await serverToMachineChannel.Writer.WriteAsync(0, cts.Token);
                            }

                            break;
                        }

                        // We don't have a paddle position yet...
                        await Task.Delay(100, cts.Token);
                    }
                }
            }, cts.Token);

            var answerTask = Task.Run(async() =>
            {
                var populationOccured    = false;
                (long X, long Y)position = (0, 0);
                while (await machineToServerChannel.Reader.WaitToReadAsync(cts.Token))
                {
                    position.X = await machineToServerChannel.Reader.ReadAsync(cts.Token);
                    position.Y = await machineToServerChannel.Reader.ReadAsync(cts.Token);

                    var movePaddle = false;
                    if (position.X == -1 && position.Y == 0)
                    {
                        score             = await machineToServerChannel.Reader.ReadAsync(cts.Token);
                        populationOccured = true;
                    }
                    else
                    {
                        var tile = (Tile)await machineToServerChannel.Reader.ReadAsync(cts.Token);
                        lock (cellTiles)
                        {
                            cellTiles[position] = tile;
                        }

                        movePaddle = cellTiles[position] == Tile.Ball;
                    }

                    if (inputData.PrintMap)
                    {
                        this.PrintMap(GetMap(cellTiles), score);
                        await Task.Delay(10, cts.Token);
                    }

                    if (movePaddle)
                    {
                        ballPosSemaphore.Release();
                    }
                }

                return(cellTiles.Count(t => t.Value == Tile.Block), score);
            }, cts.Token);

            Task.Run(async() => { await intMachine.ProcessAsync(data, cts.Token); }, cts.Token);

            return(answerTask.Result);
        }