Esempio n. 1
0
        private static void LabelizeFile(string file, IntcodeDecompiler decom)
        {
            long[] data = InputHelper.GetIntcodeFromFile(file);

            string text = String.Join(Environment.NewLine, decom.Labelize(data));

            File.WriteAllText(InputHelper.GetOutputPathForFile(file + "_labelized"), text);
            Console.WriteLine(file + "_labelized ok");
        }
Esempio n. 2
0
        public static void Trace()
        {
            long[] data = InputHelper.GetIntcodeFromFile("9");

            IntcodeComputer i = new IntcodeComputer(data, IntcodeMode.Trace);

            i.Run();

            File.WriteAllText(InputHelper.GetOutputPathForFile("9_trace"), String.Join(Environment.NewLine, i.GetTrace()));
        }
Esempio n. 3
0
        private static (int, string) GetFastestPathToAllKeys(Maze m, string file)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            List <MazePath> paths = MakeAllPathsList(m);

            sw.Stop();
            Console.WriteLine($"All {paths.Count} paths from entrance/keys to keys have been devised in {sw.ElapsedMilliseconds} ms");
            File.WriteAllText(InputHelper.GetOutputPathForFile(file), String.Join(Environment.NewLine, paths));
            Console.WriteLine($"Paths saved to {file}.txt");

            sw.Reset();
            sw.Start();
            List <(int steps, string keyOrder)> orders = GetPossiblePaths(paths, m.Cells.OfType <MazeKey>().Count());

            sw.Stop();
            Console.WriteLine($"All {orders.Count} key orders have been mapped in {sw.ElapsedMilliseconds} ms");
            return(orders.OrderBy(o => o.steps).First());
        }
Esempio n. 4
0
        public static void PartOne()
        {
            long[] data = InputHelper.GetIntcodeFromFile("19");

            StringBuilder sb = new StringBuilder();

            for (int y = 810; y < 1047; y++)
            {
                for (int x = 840; x < 1047; x++)
                {
                    IntcodeComputer com = new IntcodeComputer(data, IntcodeMode.Quiet);
                    com.InputQueue.Enqueue(x);
                    com.InputQueue.Enqueue(y);
                    com.Run();
                    if (com.OutputQueue.Dequeue() == 0)
                    {
                        sb.Append('.');
                    }
                    else
                    {
                        if (y >= 812 && x >= (845 + 84) &&
                            y < 912 && x < (945 + 84))
                        {
                            sb.Append('X');
                        }
                        else
                        {
                            sb.Append('#');
                        }
                    }
                }
                sb.AppendLine();
            }

            File.WriteAllText(InputHelper.GetOutputPathForFile("19_big_offset"), sb.ToString());
        }