public function parseInstructions($instructions)
 {
     foreach (str_split($instructions) as $instruction) {
         if ($instruction == '(') {
             $this->instructionCount++;
             $this->elevator->goUp();
         } elseif ($instruction == ')') {
             $this->instructionCount++;
             $this->elevator->goDown();
         }
     }
 }
 public function parseInstructions($instructions)
 {
     foreach (str_split($instructions) as $instruction) {
         if ('(' === $instruction) {
             $this->instructionPosition++;
             $this->elevator->goUp();
         } elseif (')' === $instruction) {
             $this->instructionPosition++;
             $this->elevator->goDown();
         }
     }
 }
Esempio n. 3
0
 public function __invoke()
 {
     $input = file_get_contents(__DIR__ . '/../../data/day1.txt');
     $elevator = new Elevator();
     foreach (str_split($input) as $char) {
         if ($char == '(') {
             $elevator->goUp();
         } elseif ($char == ')') {
             $elevator->goDown();
         }
     }
     echo 'Floor: ' . $elevator->floor();
 }