Example #1
0
        static void PartA()
        {
            List <InstructionBits> testProgram = ReadInput();
            Memory memory = new Memory();
            int    ip     = 0;

            while ((ip >= 0) && (ip < testProgram.Count))
            {
                InstructionBits bits = testProgram[ip];
                instructions[bits.opcode].Execute(bits, ref memory);
                memory[ipRegister]++;
                ip = memory[ipRegister];
            }
            Console.WriteLine("Part A: Result is " + memory[0] + ".");
        }
Example #2
0
        static List <InstructionBits> ReadInput()
        {
            List <InstructionBits> instructions = new List <InstructionBits>();
            string       path   = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\..\input.txt");
            StreamReader reader = File.OpenText(path);
            string       line   = reader.ReadLine();
            string       s      = new string(line.Where(Char.IsDigit).ToArray());

            ipRegister = int.Parse(s);
            while ((line = reader.ReadLine()) != null)
            {
                int             i      = 0;
                string[]        v      = line.Split(' ');
                int             opcode = opcodes[v[i++]];
                InstructionBits bits   = new InstructionBits(opcode, int.Parse(v[i++]), int.Parse(v[i++]), int.Parse(v[i++]));
                instructions.Add(bits);
            }
            return(instructions);
        }
Example #3
0
 public override void Execute(InstructionBits i, ref Memory m)
 {
     m[i.C] = i.A;
 }
Example #4
0
 public override void Execute(InstructionBits i, ref Memory m)
 {
     m[i.C] = (m[i.A] == m[i.B]) ? 1 : 0;
 }
Example #5
0
 public abstract void Execute(InstructionBits i, ref Memory m);