function findRotation($p, $boardX, $solutions) { $tmp = rotateBoard($p, $boardX); // Rotated 90 if (in_array($tmp, $solutions)) { } else { $solutions[] = $tmp; } $tmp = rotateBoard($tmp, $boardX); // Rotated 180 if (in_array($tmp, $solutions)) { } else { $solutions[] = $tmp; } $tmp = rotateBoard($tmp, $boardX); // Rotated 270 if (in_array($tmp, $solutions)) { } else { $solutions[] = $tmp; } // Reflected $tmp = array_reverse($p); if (in_array($tmp, $solutions)) { } else { $solutions[] = $tmp; } $tmp = rotateBoard($tmp, $boardX); // Reflected and Rotated 90 if (in_array($tmp, $solutions)) { } else { $solutions[] = $tmp; } $tmp = rotateBoard($tmp, $boardX); // Reflected and Rotated 180 if (in_array($tmp, $solutions)) { } else { $solutions[] = $tmp; } $tmp = rotateBoard($tmp, $boardX); // Reflected and Rotated 270 if (in_array($tmp, $solutions)) { } else { $solutions[] = $tmp; } return $solutions; }
/** * find rotations of a solution * @param array $row * @param int $board * @param array $solutions * @return array */ function findRotation($row, $board, $solutions) { $tmp = rotateBoard($row, $board); // Rotated 90 if (!in_array($tmp, $solutions)) { $solutions[] = $tmp; } $tmp = rotateBoard($tmp, $board); // Rotated 180 if (!in_array($tmp, $solutions)) { $solutions[] = $tmp; } $tmp = rotateBoard($tmp, $board); // Rotated 270 if (!in_array($tmp, $solutions)) { $solutions[] = $tmp; } $tmp = array_reverse($row); // Reflected if (!in_array($tmp, $solutions)) { $solutions[] = $tmp; } $tmp = rotateBoard($tmp, $board); // Reflected and Rotated 90 if (!in_array($tmp, $solutions)) { $solutions[] = $tmp; } $tmp = rotateBoard($tmp, $board); // Reflected and Rotated 180 if (!in_array($tmp, $solutions)) { $solutions[] = $tmp; } $tmp = rotateBoard($tmp, $board); // Reflected and Rotated 270 if (!in_array($tmp, $solutions)) { $solutions[] = $tmp; } return $solutions; }