示例#1
0
    public bool Test(string modelNr)
    {
        var input = new Queue <int>(modelNr.AsEnumerable().Select(Helpers.ParseChar));

        alu.Run(program, input);
        return(alu.Value("z") == 0);
    }
示例#2
0
        public void Part2()
        {
            ALU alu = new ALU(File.ReadAllLines("Day24Input.txt"));

            List <int> modelNumber = new List <int>()
            {
                9, 1, 8, 1, 1, 2, 1, 1, 6, 1, 1, 9, 8, 1
            };

            alu.Run(modelNumber.ToArray());

            Assert.Equal(0, alu.Z);
        }
示例#3
0
        static void Main(string[] args)
        {
            var is_test  = false;
            var filename = is_test ? "sample.txt" : "input.txt";
            var lines    = File.ReadAllLines(filename).TakeWhile(x => x.Length > 0);
            // var input = is_test ? "1" : "`00000000000001";

            // var input = new int[14] { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
            var input = "83499629198498".Select(x => x - '0').ToArray(); // för högt för lägsta

            // var input = "93499629198499".Select(x => x - '0').ToArray();
            // Denna ger 23: 94497429698943
            // var input = "93499629698999".Select(x => x - '0').ToArray(); // denna var korrekt
            // 1 <--> 14
            // 2 <--> 13
            // 3 <--> 4
            // 5 <--> 6
            // 7 <--> 8
            // 9 <--> 12
            // 10 <--> 11
            // "11164118121471" --> Minsta



            while (true)
            {
                Console.Write("              ");
                for (int i = 0; i < 14; i++)
                {
                    Console.Write($"{(char)('0' + input[i]),14}");
                }
                Console.WriteLine();

                var alu       = new ALU(lines);
                var responses = alu.Run(input, false);

                for (int i = 0; i <= 14; i++)
                {
                    Console.Write($"{responses[i],14}");
                }
                Console.WriteLine();
                int            index = -1;
                ConsoleKeyInfo key   = default;
                while (index < 0)
                {
                    key   = Console.ReadKey(true);
                    index = key.Key switch {
                        ConsoleKey.Q => 0,
                        ConsoleKey.W => 1,
                        ConsoleKey.E => 2,
                        ConsoleKey.R => 3,
                        ConsoleKey.T => 4,
                        ConsoleKey.Y => 5,
                        ConsoleKey.U => 6,
                        ConsoleKey.I => 7,
                        ConsoleKey.O => 8,
                        ConsoleKey.P => 9,
                        ConsoleKey.A => 10,
                        ConsoleKey.S => 11,
                        ConsoleKey.D => 12,
                        ConsoleKey.F => 13,
                        ConsoleKey.Escape => 100,
                        _ => - 1
                    };
                    if (index == -1)
                    {
                        Console.WriteLine(key.Key);
                        Console.WriteLine(key.Modifiers);
                        Console.WriteLine(key.KeyChar);
                    }
                }
                if (index == 100)
                {
                    return;
                }
                input[index] += key.Modifiers == ConsoleModifiers.Shift ? -1 : 1;
            }



            // for (int i = 0; i < 2; i++) {
            //     bool stop = false;
            //     do {
            //         Console.WriteLine(new string(input.Select(x => (char)('0' + x)).ToArray()));
            //         try {
            //             var alu = new ALU(lines);
            //             alu.Run(input);
            //             input[i]--;
            //             // stop = true;
            //         }
            //         catch {
            //             input[i]--;
            //             stop = false;
            //         }
            //     } while (!stop && input[i] >= 0);
            // }
        }
    }