コード例 #1
0
ファイル: Part1.php プロジェクト: baruica/AdventOfCode2015
 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";
 }
コード例 #2
0
ファイル: Puzzle1.php プロジェクト: dstockto/AdventOfCode2015
 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";
 }
コード例 #3
0
ファイル: Part2.php プロジェクト: baruica/AdventOfCode2015
 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";
 }
コード例 #4
0
 /**
  * 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();
             }
         }
     }
 }
コード例 #5
0
ファイル: Puzzle2.php プロジェクト: dstockto/AdventOfCode2015
 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";
 }
コード例 #6
0
ファイル: Puzzle2.php プロジェクト: dstockto/AdventOfCode2015
 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";
 }