function isCircular($num) { if (!isPrime($num)) { return false; } if ($num > 10) { $numstr = (string) $num; if (strstr($numstr, "0") || strstr($numstr, "5") || strstr($numstr, "2") || strstr($numstr, "4") || strstr($numstr, "6") || strstr($numstr, "8")) { return false; } $len = strlen($numstr); for ($i = 0; $i < $len - 1; $i++) { $numstr = (string) $num; $num = rotateLeft($numstr); if (!isPrime((int) $num)) { return false; } } } return true; }
function carscript() { global $posx, $posy, $nextPosx, $nextPosy, $DIYleftWheel, $DIYrightWheel, $prevDIYLeftWheel, $direction; // Car logic for boundaries // Recalculate position if ($DIYleftWheel == 1 && $prevDIYLeftWheel != $DIYleftWheel) { recalculateCoordinates(); } $prevDIYLeftWheel = $DIYleftWheel; if ($nextPosx < 0 || $nextPosx > BOUNDARY_X || $nextPosy < 0 || $nextPosy > BOUNDARY_Y) { // Out of boundary. Handle same as obstacle. echo "It has to stop and rotate" . $direction . "!!"; rotateLeft(160); $direction = $direction + 160; $carIsRunning = TRUE; movementLogic(); recalculateCoordinates(); echo "Rotated... in bounds again"; } else { // we are still inside the boundary. Update posx and posy and execute normal logic. $posx = $nextPosx; $posy = $nextPosy; movementLogic(); } var_dump($posx . ' ' . $posy . ' ' . $DIYleftWheel . ' ' . $prevDIYLeftWheel); }