| Total Complexity | 8 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 7 | class Day1 implements Day |
||
| 8 | { |
||
| 9 | const FLOOR_UP = '('; |
||
| 10 | const FLOOR_DOWN = ')'; |
||
| 11 | |||
| 12 | private array $directions = []; |
||
| 13 | |||
| 14 | public function loadInput(): void |
||
| 15 | { |
||
| 16 | $filepath = __DIR__ . "/input/day-1.txt"; |
||
| 17 | |||
| 18 | $this->directions = str_split(file_get_contents($filepath)); |
||
| 19 | } |
||
| 20 | |||
| 21 | public function solve() |
||
| 22 | { |
||
| 23 | printf("The resulting floor is: %s\n", $this->calculateFloor()); |
||
| 24 | } |
||
| 25 | |||
| 26 | public function calculateFloor(int $floor = 0): int |
||
| 27 | { |
||
| 28 | foreach ($this->directions as $direction) { |
||
| 29 | if ($direction === self::FLOOR_UP) { |
||
| 30 | $floor++; |
||
| 31 | } elseif ($direction === self::FLOOR_DOWN) { |
||
| 32 | $floor--; |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | return $floor; |
||
| 37 | } |
||
| 38 | |||
| 39 | public function setDirections(array $directions): void |
||
| 42 | } |
||
| 43 | |||
| 44 | public function getDirections(): array |
||
| 45 | { |
||
| 47 | } |
||
| 48 | } |