This is an error 404
There are `0` results
preferences:
173.32 ms | 1403 KiB | 7 Q<?php
class Bathroom {
const LEFT = [2, 5, 8, 3, 6, 9];
const UP = [4, 5, 6, 7, 8, 9];
const RIGHT = [1, 2, 4, 5, 7, 8];
const DOWN = [1, 2, 3, 4, 5, 6];
private $number = 5;
private $code;
public function left()
{
if (in_array($this->number, self::LEFT)) {
$this->number -= 1;
}
}
public function up()
{
if (in_array($this->number, self::UP)) {
$this->number -= 3;
}
}
public function right()
{
if (in_array($this->number, self::RIGHT)) {
$this->number += 1;
}
}
public function down()
{
if (in_array($this->number, self::DOWN)) {
$this->number += 3;
}
}
public function getCode()
{
return $this->code;
}
public function updateCode()
{
$this->code .= $this->number;
}
}
$input = 'ULL
RRDDD
LURDL
UUUUD';
$inputs = (explode("\n", $input));
$bathroom = new Bathroom;
foreach ($inputs as $input) {
$len = strlen($input);
for ($i = 0; $i < $len; $i++) {
switch ($input{$i}) {
case 'U':
$bathroom->up();
break;
case 'L':
$bathroom->left();
break;
case 'R':
$bathroom->right();
break;
case 'D':
$bathroom->down();
break;
}
}
$bathroom->updateCode();
}
echo $bathroom->getCode();