예제 #1
0
        public void Puzzle()
        {
            permutations = new List <int[]>();
            int[] ampInput = { 0, 1, 2, 3, 4 };
            permutate(ampInput, ampInput.Length);
            string input = System.IO.File.ReadAllText(@"K:\Android projects\AdventOfCode2019\input7.txt");

            Comp[] computers = new Comp[] { new Comp(input), new Comp(input), new Comp(input), new Comp(input), new Comp(input) };
            long   counter   = 0;
            string perm      = "";
            long   output    = 0;

            foreach (int[] p in permutations)
            {
                int i = 0;
                output = 0;
                foreach (Comp comp in computers)
                {
                    comp.Puzzle(new int[] { p[i], (int)output }, 0);
                    output = comp.outputArr[comp.outputArr.Length - 1];
                    i++;
                }
                perm    = output > counter ? p[0].ToString() + p[1].ToString() + p[2].ToString() + p[3].ToString() + p[4].ToString() : perm;
                counter = output > counter ? output : counter;
            }
            Console.WriteLine("Biggest power thrust: " + counter + "\nFrom permutation    : " + perm);
            computers = new Comp[] { new Comp(input), new Comp(input), new Comp(input), new Comp(input), new Comp(input) };
            int[] ampInput2 = { 5, 6, 7, 8, 9 };
            permutations = new List <int[]>();
            permutate(ampInput2, ampInput2.Length);

            counter = 0;
            foreach (int[] p in permutations)
            {
                output = 0;
                bool firstRound = true;
                bool done       = false;
                while (!done)
                {
                    if (firstRound)
                    {
                        computers[0].Puzzle(new int[] { p[0], (int)output }, 0); //A
                        output = computers[0].outputArr[computers[0].outputArr.Length - 1];
                        computers[1].Puzzle(new int[] { p[1], (int)output }, 1); //B
                        output = computers[1].outputArr[computers[1].outputArr.Length - 1];
                        computers[2].Puzzle(new int[] { p[2], (int)output }, 2); //C
                        output = computers[2].outputArr[computers[2].outputArr.Length - 1];
                        computers[3].Puzzle(new int[] { p[3], (int)output }, 3); //D
                        output = computers[3].outputArr[computers[3].outputArr.Length - 1];
                        computers[4].Puzzle(new int[] { p[4], (int)output }, 4); //E
                        output     = computers[4].outputArr[computers[4].outputArr.Length - 1];
                        firstRound = false;
                    }
                    else
                    {
                        computers[0].Puzzle(new int[] { (int)output }, 0); //A
                        output = computers[0].outputArr[computers[0].outputArr.Length - 1];
                        computers[1].Puzzle(new int[] { (int)output }, 1); //B
                        output = computers[1].outputArr[computers[1].outputArr.Length - 1];
                        computers[2].Puzzle(new int[] { (int)output }, 2); //C
                        output = computers[2].outputArr[computers[2].outputArr.Length - 1];
                        computers[3].Puzzle(new int[] { (int)output }, 3); //D
                        output = computers[3].outputArr[computers[3].outputArr.Length - 1];
                        computers[4].Puzzle(new int[] { (int)output }, 4); //E
                        output = computers[4].outputArr[computers[4].outputArr.Length - 1];
                    }
                    if (computersDone(computers))
                    {
                        done   = true;
                        output = computers[4].outputArr[computers[4].outputArr.Length - 1];
                        resetComputers(computers);
                    }
                }

                perm    = output > counter ? p[0].ToString() + p[1].ToString() + p[2].ToString() + p[3].ToString() + p[4].ToString() : perm;
                counter = output > counter ? output : counter;
            }
            Console.WriteLine("Biggerest power thrust: " + counter + "\nFrom permutation      : " + perm);
        }
예제 #2
0
        public void Puzzle()
        {
            Comp c = new Comp(System.IO.File.ReadAllText(@"K:\Android projects\AdventOfCode2019\input5.txt"), true);

            c.Puzzle(0);
        }
예제 #3
0
        public void Puzzle()
        {
            string       input = System.IO.File.ReadAllText(@"K:\Android projects\AdventOfCode2019\input11.txt");
            Comp         c     = new Comp(input);
            List <int[]> moves = new List <int[]>();

            int[] tile      = { 0, 0, 1 };
            int   direction = 1;
            int   pointer   = 0;

            while (c.outputCode != 99)
            {
                c.Puzzle(new int[] { tile[2] }, 0);
                tile[2] = (int)c.outputArr[0 + pointer];
                if (!tileExists(tile, moves))
                {
                    moves.Add(new int[] { tile[0], tile[1], tile[2] });
                }
                direction = (int)c.outputArr[1 + pointer] == 0 ? direction - 1 : direction + 1;
                if (direction < 0)
                {
                    direction = 3;
                }
                else if (direction > 3)
                {
                    direction = 0;
                }
                pointer += 2;

                var newCoord = updateLocation(tile[0], tile[1], direction);
                tile[0] = newCoord[0];
                tile[1] = newCoord[1];
                var newTile = fetchTile(tile, moves);
                if (newTile[2] != 3)
                {
                    tile[2] = newTile[2];
                }
                else
                {
                    tile[2] = 0;
                }
            }
            Console.WriteLine(moves.Count);
            int[] xbounds = new int[2];
            int[] ybounds = new int[2];
            foreach (int[] move in moves)
            {
                xbounds[0] = xbounds[0] < move[0] ? xbounds[0] : move[0];
                xbounds[1] = xbounds[1] > move[0] ? xbounds[1] : move[0];
                ybounds[0] = ybounds[0] < move[1] ? ybounds[0] : move[1];
                ybounds[1] = ybounds[1] > move[1] ? ybounds[1] : move[1];
            }
            int[,] hull = new int[xbounds[1] - xbounds[0] + 1, ybounds[1] - ybounds[0] + 1];
            foreach (int[] move in moves)
            {
                hull[move[0], move[1]] = move[2];
            }
            for (int i = 0; i < hull.GetLength(1); i++)
            {
                for (int j = 0; j < hull.GetLength(0); j++)
                {
                    switch (hull[j, i])
                    {
                    case 0:

                        Console.Write(".");
                        break;

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