/** * Solve the 8 Queens puzzle * @return array A list of solutions */ function solve8queens2() { $board = 8; // create the different possible rows for ($x = 0; $x < $board; ++$x) { $row[$x] = 1 << $x; } // create all the possible orders of rows $solcount = 0; $solutions = array(); while ($row != false) { if (checkBoard($row, $board)) { if (!in_array($row, $solutions)) { $solutions[] = $row; $solutions = findRotation($row, $board, $solutions); ++$solcount; } } $row = nextPermutation($row); } return $solutions; }
} ++$a; } return true; } if (isset($_POST['process']) && isset($_POST['boardX'])) { //Within here is the code that needs to be run if process is clicked. //First I need to create the different possible rows for ($x = 0; $x < $boardX; ++$x) { $row[$x] = 1 << $x; } //Now I need to create all the possible orders of rows, will be equal to [boardY]! $solcount = 0; $solutions = array(); while ($row != false) { if (checkBoard($row, $boardX)) { if (!in_array($row, $solutions)) { $solutions[] = $row; renderBoard($row, $boardX); $solutions = findRotation($row, $boardX, $solutions); ++$solcount; } } $row = pc_next_permutation($row); } echo "<br><br>    Rows/Columns: " . $boardX . "<br>    Unique Solutions: " . $solcount . "<br>    Total Solutions: " . count($solutions) . " - Note: This includes symmetrical solutions<br>"; //print_r($solutions); } //This code collects the starting parameters echo <<<_END <form name="input" action="queens.php" method="post">