예제 #1
0
 public void Run()
 {
     computer.LoadProgram(FileUtils.LoadDataFor(13))
     .SetInput(() => joystickInput)
     .SetOutput(GetX)
     .Run();
 }
예제 #2
0
 private Task RunComputerWithWiredIO(long phase, BlockingCollection <long> input, BlockingCollection <long> output)
 => Task.Run(()
             => new IntComputer()
             .LoadProgram(FileUtils.LoadDataFor(7))
             .SetInput(() => input.Take())//InputEnumerator(phase, input))
             .SetOutput((o) => output.Add(o))
             .Run());
예제 #3
0
        public Day9()
        {
            var computer = new IntComputer();

            computer.LoadProgram(FileUtils.LoadDataFor(9)).SetInput(() => 1).SetOutput((o) => _answer1 = o).Run();
            computer.LoadProgram(FileUtils.LoadDataFor(9)).SetInput(() => 2).SetOutput((o) => _answer2 = o).Run();
        }
예제 #4
0
        public Day2()
        {
            var computer = new IntComputer();

            _answer1 = computer.LoadProgram(FileUtils.LoadDataFor(2)).Using(12, 2).Run().MemoryZeroAddress;
            _answer2 = FindVerbAndNounForOutput(computer, 19690720);
        }
예제 #5
0
        public PaintingRobot(long startingPointColor = 0)
        {
            panelsGridPaintStatus.Add(currentPosition, startingPointColor);

            computer.LoadProgram(FileUtils.LoadDataFor(11))
            .SetInput(ColorInput)
            .SetOutput(Paint)
            .Run();
        }
예제 #6
0
        public long GetDust()
        {
            var movements  = GetAsciiInput(new string[] { "A,B,A,B,C,C,B,C,B,A", "R,12,L,8,R,12", "R,8,R,6,R,6,R,8", "R,8,L,8,R,8,R,4,R,4" });
            var asciiInput = new Queue <long>(movements);

            computer.LoadProgram(FileUtils.LoadDataFor(17))
            .SetMemory(2)
            .SetOutput(DustCollected)
            .SetInput(() => asciiInput.Dequeue())
            .Run();

            return(dustCollected);
        }
예제 #7
0
        private int FindVerbAndNounForOutput(IntComputer computer, int output)
        {
            for (var noun = 0; noun < 100; noun++)
            {
                for (var verb = 0; verb < 100; verb++)
                {
                    if (computer
                        .LoadProgram(FileUtils.LoadDataFor(2))
                        .Using(noun, verb)
                        .Run()
                        .MemoryZeroAddress == output)
                    {
                        return((100 * noun) + verb);
                    }
                }
            }

            return(0);
        }
예제 #8
0
        public Scaffold()
        {
            computer.LoadProgram(FileUtils.LoadDataFor(17))
            .SetOutput(CameraOutput)
            .Run();

            FindIntersections();

            //Print(true);

            RobotPosition currentPosition = screen.Where(s => !(s.Value == '#' || s.Value == '.')).Select(s => new RobotPosition(s.Value, s.Key)).FirstOrDefault();
            List <Point>  scaffoldPath    = screen.Where(s => s.Value == 35).Select(s => s.Key).ToList();

            scaffoldPath.AddRange(intersections);

            FindScaffoldPath(scaffoldPath, currentPosition);

            Console.WriteLine(GetDust());
        }