コード例 #1
0
        public static void Step1()
        {
            IntCodeMachine.RunUntilStopped(new long[] { 1002, 5, 3, 5, 99, 33 })
            .Memory[5].Should().Be(99);

            var machine = IntCodeMachine.RunUntilStopped(Input, new long[] { 1 });

            machine.Outputs.Last().Should().Be(7839346);
        }
コード例 #2
0
ファイル: Day07.cs プロジェクト: Skytherin/AdventOfCode
        private static long InternalStep1(string str)
        {
            var s = str.ToLongArray();

            return(new long[] { 0, 1, 2, 3, 4 }.Permute().Max(permutation =>
            {
                var amplifier = IntCodeMachine.RunUntilStopped(s, permutation[0], 0);
                amplifier = IntCodeMachine.RunUntilStopped(s, permutation[1], amplifier.Outputs.First());
                amplifier = IntCodeMachine.RunUntilStopped(s, permutation[2], amplifier.Outputs.First());
                amplifier = IntCodeMachine.RunUntilStopped(s, permutation[3], amplifier.Outputs.First());
                amplifier = IntCodeMachine.RunUntilStopped(s, permutation[4], amplifier.Outputs.First());
                return amplifier.Outputs.First();
            }));
        }
コード例 #3
0
        public static void Step1()
        {
            IntCodeMachine.RunUntilStopped(new[]
                                           { 109L, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99 })
            .Outputs.Should().BeEquivalentTo(new[]
                                             { 109L, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99 });

            IntCodeMachine.RunUntilStopped(new long[] { 1102, 34915192, 34915192, 7, 4, 7, 99, 0 })
            .Outputs.Single().Decimate().Should().HaveCount(16);

            IntCodeMachine.RunUntilStopped(new long[] { 104, 1125899906842624, 99 })
            .Outputs.Single().Should().Be(1125899906842624);

            var result = IntCodeMachine.RunUntilStopped(Input, 1);

            result.Outputs.Single().Should().Be(3989758265L);

            var result2 = IntCodeMachine.RunUntilStopped(Input, 2);

            result2.Outputs.Single().Should().Be(76791L);
        }
コード例 #4
0
        public static void Step2()
        {
            IntCodeMachine.RunUntilStopped(new long[] { 3, 9, 8, 9, 10, 9, 4, 9, 99, -1, 8 },
                                           new long[] { 8 }).Outputs.Single().Should().Be(1);
            IntCodeMachine.RunUntilStopped(new long[] { 3, 9, 8, 9, 10, 9, 4, 9, 99, -1, 8 },
                                           new long[] { 7 }).Outputs.Single().Should().Be(0);

            var example = new long[]
            {
                3, 21, 1008, 21, 8, 20, 1005, 20, 22, 107, 8, 21, 20, 1006, 20, 31,
                1106, 0, 36, 98, 0, 0, 1002, 21, 125, 20, 4, 20, 1105, 1, 46, 104,
                999, 1105, 1, 46, 1101, 1000, 1, 20, 4, 20, 1105, 1, 46, 98, 99
            };

            IntCodeMachine.RunUntilStopped(example, 6).Outputs.Single().Should().Be(999);
            IntCodeMachine.RunUntilStopped(example, 7).Outputs.Single().Should().Be(999);
            IntCodeMachine.RunUntilStopped(example, 8).Outputs.Single().Should().Be(1000);
            IntCodeMachine.RunUntilStopped(example, 9).Outputs.Single().Should().Be(1001);
            IntCodeMachine.RunUntilStopped(example, 10).Outputs.Single().Should().Be(1001);

            var machine = IntCodeMachine.RunUntilStopped(Input, 5);

            machine.Outputs.Last().Should().Be(447803);
        }