This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Solves the n-Queen puzzle in O(n!) | |
* Let p[r] be the column of the queen on the rth row (must be exactly 1 queen per row) | |
* There also must be exactly 1 queen per column and hence p must be a permuation of (0 until n) | |
* There must be n distinct (col + diag) and n distinct (col - diag) for each queen (else bishop attacks) | |
* @return returns a Iterator of solutions | |
* Each solution is an array p of length n such that p[i] is the column of the queen on the ith row | |
*/ | |
def nQueens(n: Int): Iterator[Seq[Int]] = | |
(0 until n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.*; | |
import javafx.geometry.Pos; | |
import javafx.scene.*; | |
import javafx.scene.control.Label; | |
import javafx.scene.layout.*; | |
import javafx.scene.paint.Color; | |
import javafx.stage.*; | |
import javax.imageio.ImageIO; | |
import java.io.IOException; |