$this->step($char); } return count($this->visited); } public function step2($dir) { $xField = 'x' . $this->turn; $yField = 'y' . $this->turn; $this->{$xField} += $this->dir[$dir][0]; $this->{$yField} += $this->dir[$dir][1]; $key = $this->{$xField} . 'x' . $this->{$yField}; if (!isset($this->visited[$key])) { $this->visited[$key] = 0; } $this->visited[$key]++; } public function part2() { $this->read(); $this->visited = ['0x0' => 2]; foreach ($this->input as $index => $char) { $this->turn = $index % 2 === 0 ? 'Santa' : 'Robo'; $this->step2($char); } return count($this->visited); } } $houses = new Houses(); echo "part1: " . $houses->countVisited() . "\n\n"; echo "part2: " . $houses->part2();