*/ class Floors { protected $floor = 0; protected $dir = array('(' => 'up', ')' => 'down'); public function up() { $this->floor++; } public function down() { $this->floor--; } public function read($input) { $chars = str_split($input); $basement = false; foreach ($chars as $i => $char) { $fn = $this->dir[$char]; $this->{$fn}(); if ($this->floor == -1 && !$basement) { $basement = true; echo "BASEMENT AT POSITION: " . ($i + 1); } } var_dump($this->floor); } } $f = new Floors(); $f->read(file_get_contents(__DIR__ . '/input/1'));