Use match instead of switch
This commit is contained in:
parent
46833e668a
commit
ddfa50a6af
22
src/Day2.php
22
src/Day2.php
@ -25,22 +25,11 @@ class Day2 extends AbstractCommand
|
|||||||
*/
|
*/
|
||||||
[$direction, $distance] = explode(' ', $current);
|
[$direction, $distance] = explode(' ', $current);
|
||||||
|
|
||||||
switch ($direction) {
|
match ($direction) {
|
||||||
case 'forward':
|
'forward' => $horizontal += $distance,
|
||||||
$horizontal += $distance;
|
'down' => $depth += $distance,
|
||||||
|
'up' => $depth -= $distance,
|
||||||
break;
|
};
|
||||||
|
|
||||||
case 'down':
|
|
||||||
$depth += $distance;
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'up':
|
|
||||||
$depth -= $distance;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $depth * $horizontal;
|
return $depth * $horizontal;
|
||||||
@ -63,6 +52,7 @@ class Day2 extends AbstractCommand
|
|||||||
*/
|
*/
|
||||||
[$direction, $distance] = explode(' ', $current);
|
[$direction, $distance] = explode(' ', $current);
|
||||||
|
|
||||||
|
// Can't use 'match' here because of the multiple expressions for 'forward'.
|
||||||
switch ($direction) {
|
switch ($direction) {
|
||||||
case 'forward':
|
case 'forward':
|
||||||
$horizontal += $distance;
|
$horizontal += $distance;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user