forked from DhanushNehru/Hacktoberfest2025
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNQueensAndNKnights.java
More file actions
29 lines (22 loc) · 823 Bytes
/
NQueensAndNKnights.java
File metadata and controls
29 lines (22 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.ArrayList;
import java.util.List;
public class NQueensAndNKnights {
public static void main(String[] args) {
int n = 8; // Adjust the board size as needed
// N-Queens
List<List<Integer>> nQueensSolutions = solveNQueens(n);
System.out.println("N-Queens solutions:");
for (List<Integer> solution : nQueensSolutions) {
printSolution(solution);
}
// N-Knights
List<List<Integer>> nKnightsSolutions = solveNKnights(n);
System.out.println("N-Knights solutions:");
for (List<Integer> solution : nKnightsSolutions) {
printSolution(solution);
}
}
// N-Queens code (same as before)
// N-Knights code (same as before)
// ... (rest of the code for both N-Queens and N-Knights)
}