- preg_match: documentation ( source)
- explode: documentation ( source)
<?php
$input = "turn on 0,0 through 999,999";
$lights = [[]];
for($i = 0; $i<1000; $i++){
for($j = 0; $j<1000; $j++){
$lights[$i][$j] = 0;
}
}
explode("\n",$input);
function action($s){
$on = preg_match("/turn on/",$s);
$off = preg_match("/turn off/",$s);
$toggle = preg_match("/toggle/",$s);
if($on > 0){
return 1;
}
else if($off>0){
return 2;
}
else if($toggle>0){
return 3;
}
}
echo action($input);
?>