Пример #1
0
        public static void FindVerbAndNoun(string filePath, int output)
        {
            List <int> memory = ParseInput(filePath);

            for (int i = 0; i <= 1000000000; i++)
            {
                for (int noun = 0; noun <= 99; noun++)
                {
                    for (int verb = 0; verb <= 99; verb++)
                    {
                        List <int> intcode = new List <int>(memory);
                        intcode[1] = noun;
                        intcode[2] = verb;
                        Emulator.Emulator emulator = new Emulator.Emulator(intcode);
                        intcode = emulator.IterateThroughIntcode();
                        if (OutputChecker(intcode, output))
                        {
                            Console.WriteLine(100 * noun + verb);
                            return;
                        }
                        ResetMemory(intcode);
                    }
                }
            }

            Console.WriteLine("No noun and verb found for finding the output.");
        }
Пример #2
0
 public static void PlayManual(int problemnum, int seed, string[] powerPhrases, int delay)
 {
     var problem = ProblemsSet.GetProblem(problemnum);
     var game = new ConsoleGame(problem, problem.sourceSeeds[seed], powerPhrases);
     var emulator = new Emulator(game, delay);
     emulator.Run();
 }
Пример #3
0
 public static void PlayAuto(int problemnum, string solution, int seed, string[] powerPhrases, int delay)
 {
     var problem = ProblemsSet.GetProblem(problemnum);
     var game = new Game(problem, new Output() { solution = solution, seed = problem.sourceSeeds[seed] }, powerPhrases);
     var emulator = new Emulator(game, delay);
     emulator.Run();
 }
Пример #4
0
 public string Solve(Problem problem, int seed, string[] magicSpells)
 {
     var game = new ConsoleGame(problem, seed, magicSpells);
     var emulator = new Emulator(game, -1);
     emulator.Run();
     var solution = game.Solution;
     return solution;
 }
Пример #5
0
        public static void Day2FuncA(string filePath)
        {
            List <int>  intcode = ParseInput(filePath);
            Queue <int> input   = new Queue <int>();
            Queue <int> output  = new Queue <int>();

            input.Enqueue(5);
            Emulator.Emulator emulator = new Emulator.Emulator(intcode);
            intcode = emulator.IterateThroughIntcode();
            Console.WriteLine(intcode[0]);
        }
Пример #6
0
        public static void Day5FuncB(string filePath)
        {
            List <int>  intcode = ParseInput(filePath);
            Queue <int> output  = new Queue <int>();

            Emulator.Emulator emulator = new Emulator.Emulator(intcode, 5);
            intcode = emulator.IterateThroughIntcode();
            output  = emulator.ReadOutputs();
            while (output.Count != 0)
            {
                Console.WriteLine(output.Dequeue());
            }
        }
Пример #7
0
        public static void Day7FuncB(string filePath)
        {
            List <string> ampPhaseSettings = new List <string>();

            GetPermutations("56789", ampPhaseSettings, 0, 4);
            List <int> memory          = ParseInput(filePath);
            List <int> intcode         = new List <int>(memory);
            int        highestThruster = int.MinValue;

            foreach (string ampPhaseSetting in ampPhaseSettings)
            {
                Emulator.Emulator amplifierA = new Emulator.Emulator(intcode, int.Parse(ampPhaseSetting[0].ToString()));
                Emulator.Emulator amplifierB = new Emulator.Emulator(intcode, int.Parse(ampPhaseSetting[1].ToString()));
                Emulator.Emulator amplifierC = new Emulator.Emulator(intcode, int.Parse(ampPhaseSetting[2].ToString()));
                Emulator.Emulator amplifierD = new Emulator.Emulator(intcode, int.Parse(ampPhaseSetting[3].ToString()));
                Emulator.Emulator amplifierE = new Emulator.Emulator(intcode, int.Parse(ampPhaseSetting[4].ToString()));
                Queue <int>       inputs     = new Queue <int>();
                inputs.Enqueue(0);
                amplifierA.Inputs = inputs;
                do
                {
                    amplifierA.IterateThroughIntcode();

                    amplifierB.Inputs = amplifierA.ReadOutputs();
                    amplifierB.IterateThroughIntcode();

                    amplifierC.Inputs = amplifierB.ReadOutputs();
                    amplifierC.IterateThroughIntcode();

                    amplifierD.Inputs = amplifierC.ReadOutputs();
                    amplifierD.IterateThroughIntcode();

                    amplifierE.Inputs = amplifierD.ReadOutputs();
                    amplifierE.IterateThroughIntcode();
                    amplifierA.Inputs = amplifierE.ReadOutputs();
                } while (amplifierE.EmulatorState != Emulator.Emulator.State.Finished);

                int thrusterValue = amplifierE.ReadOutputs().Dequeue();

                if (thrusterValue > highestThruster)
                {
                    highestThruster = thrusterValue;
                }
            }

            Console.WriteLine("Highest thruster: " + highestThruster);
        }
Пример #8
0
        public static void Solve(int problemnum, int seed, string[] magicSpells, int delay, bool visualize)
        {
            var problem = ProblemsSet.GetProblem(problemnum);
            //			var solver = new MuggleProblemSolver();
            var solver = SelectSolver(problem);

            var stopwatch = Stopwatch.StartNew();
            var solution = solver.Solve(problem, problem.sourceSeeds[seed], magicSpells);
            stopwatch.Stop();

            var game = new Game(problem, new Output { seed = problem.sourceSeeds[seed], solution = solution }, magicSpells);
            if (visualize)
            {
                var emulator = new Emulator(game, delay);
                emulator.Run();
            }
            else
            {
                while (game.state == GameBase.State.UnitInGame || game.state == GameBase.State.WaitUnit)
                {
                    game.Step();
                }
                Console.WriteLine("Score=" + game.CurrentScore);
                Console.WriteLine("Time=" + stopwatch.Elapsed);
                Console.ReadKey();
            }
        }