コード例 #1
0
        public override void PartOne(IInput input, IOutput output)
        {
            var commands = AssembunnyParser.BuildParser()
                           .AddType <Out>()
                           .ParseCommands(input.Lines)
                           .ToImmutableArray();

            TextWriter display = new StringWriter();

            for (var i = 0; ; i++)
            {
                var registers = Program.EmptyRegisters;
                registers['a'] = i;

                var program = new Program(commands, registers, 0);

                var programOutput = program.RunWithOutput();

                display.WriteLine($"{i:D5}: {string.Join("", programOutput)}");

                if (IsValidSignal(programOutput))
                {
                    output.WriteProperty("Found repeating signal", i);
                    break;
                }
            }

            output.WriteBlock(() =>
            {
                return(new Panel(display.ToString() !));
            });
コード例 #2
0
        public override void PartOne(IInput input, IOutput output)
        {
            var instructions = AssembunnyParser.BuildParser()
                               .ParseCommands(input.Lines)
                               .ToImmutableArray();

            var program = Program.New(instructions)
                          .Run();

            foreach (var(register, val) in program.Registers)
            {
                output.WriteProperty($"Register '{register}'", val);
            }
        }
コード例 #3
0
        public override void PartTwo(IInput input, IOutput output)
        {
            var instructions = AssembunnyParser.BuildParser()
                               .ParseCommands(input.Lines)
                               .ToImmutableArray();

            var registers = Program.EmptyRegisters;

            registers['c'] = 1;

            var program = new Program(instructions, registers, 0)
                          .Run();

            foreach (var(register, val) in program.Registers)
            {
                output.WriteProperty($"Register '{register}'", val);
            }
        }
コード例 #4
0
        public override void PartOne(IInput input, IOutput output)
        {
            var commands = AssembunnyParser.BuildParser()
                           .ParseCommands(ApplyOptimizations(input.Content.AsString()))
                           .ToImmutableArray();

            var registers = Program.EmptyRegisters;

            registers['a'] = 7;

            var program = new Program(commands, registers, 0)
                          .Run();

            foreach (var(register, val) in program.Registers)
            {
                output.WriteProperty($"Register '{register}'", val);
            }
        }