Esempio n. 1
0
        public override (string message, object answer) SolvePart2()
        {
            LightBoard board = new LightBoard(
                turnOn: x => x + 1,
                turnOff: x => Math.Max(0, x - 1),
                toggle: x => x + 2
                );

            return("Total brightness: ", RunInstructions(board));
        }
Esempio n. 2
0
        public override (string message, object answer) SolvePart1()
        {
            LightBoard board = new LightBoard(
                turnOn: x => 1,
                turnOff: x => 0,
                toggle: x => x == 0 ? 1 : 0
                );

            return("Lit lights: ", RunInstructions(board));
        }
Esempio n. 3
0
        private int RunInstructions(LightBoard board)
        {
            foreach (Instruction instruction in _instructions)
            {
                switch (instruction.type)
                {
                case InstructionType.TurnOn:  board.TurnOn(instruction.start, instruction.end);  break;

                case InstructionType.TurnOff: board.TurnOff(instruction.start, instruction.end); break;

                case InstructionType.Toggle:  board.Toggle(instruction.start, instruction.end);  break;
                }
            }

            return(board.brightness);
        }