Exemplo n.º 1
0
 public function testElevatorStatusShouldBeGoingUp()
 {
     $elevator = new Elevator();
     $elevator->setFloor(10);
     $expected = 'moving';
     $this->assertEquals($expected, $elevator->getStatus());
 }
Exemplo n.º 2
0
 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";
 }
Exemplo n.º 3
0
 public function __invoke()
 {
     $elevator = new Elevator();
     $parser = new InstructionsParser($elevator);
     $input = file_get_contents(__DIR__ . "/../../input/Day1/Puzzle1");
     $parser->parseInstructions($input);
     echo "Final floor: " . $elevator->getFloor();
 }
Exemplo n.º 4
0
 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";
 }
Exemplo n.º 5
0
 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";
 }
Exemplo n.º 6
0
 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 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();
         }
     }
 }
Exemplo n.º 9
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();
 }