public function __invoke() { $elevator = new Elevator(); $parser = new InstructionParser($elevator); $parser->parseInstructions(file_get_contents(__DIR__ . '/../../input/day1.txt')); echo 'Final floor : ' . $elevator->getFloor() . "\n\n"; }
public function __invoke() { $instructions = file_get_contents(__DIR__ . '/../../input/Day1/input.txt'); $elevator = new Elevator(); $parser = new InstructionParser($elevator); $parser->parseInstructions($instructions); echo "Final floor: " . $elevator->getFloor() . "\n\n"; }
public function __invoke() { $elevator = new Elevator(); $parser = new InstructionParser($elevator); $floorObserver = new FloorObserver($parser); $elevator->attach($floorObserver); $parser->parseInstructions(file_get_contents(__DIR__ . '/../../input/day1.txt')); echo 'Position of the character that causes Santa to first enter the basement : ' . $floorObserver->getInstructionPosition() . "\n\n"; }
/** * Receive update from subject * @link http://php.net/manual/en/splobserver.update.php * @param \SplSubject $elevator <p> * The <b>SplSubject</b> notifying the observer of an update. * </p> * @return void * @since 5.1.0 */ public function update(\SplSubject $elevator) { if ($elevator instanceof Elevator) { if (-1 === $elevator->getFloor()) { if (null === $this->instructionPosition) { $this->instructionPosition = $this->parser->getInstructionPosition(); } } } }
public function __invoke() { $elevator = new Elevator(); $parser = new InstructionParser($elevator); $observer = new FloorObserver($parser); $elevator->attach($observer); $input = file_get_contents(__DIR__ . '/../../input/Day1/input.txt'); $parser->parseInstructions($input); echo "We went into the basement at instruction: " . $observer->getInstructionNumber() . "\n\n"; }
public function __invoke() { $light = new Light(); $grid = new Grid(1000, 1000, $light); $parser = new InstructionParser(); $input = file(__DIR__ . '/../../input/Day6/input.txt'); foreach ($input as $line) { // Parse instruction, pass to grid $commands = $parser->parseLine($line); $grid->doOperation($commands[0], $commands[1], $commands[2], $commands[3], $commands[4]); } $numberOfLights = $grid->getTotalBrightness(); echo "Total brightness: " . $numberOfLights . "\n\n"; }