Skip to content

Instantly share code, notes, and snippets.

@sajithdilshan
Created September 9, 2014 13:53
Show Gist options
  • Save sajithdilshan/e374eaac555e327d15b5 to your computer and use it in GitHub Desktop.
Save sajithdilshan/e374eaac555e327d15b5 to your computer and use it in GitHub Desktop.
Input: Empty 8x8 matrices: Board, Attacked
Output: 8x8 matrix with 8 queens placed; Board
EightQueenRandomizedAlgo(Board, Attacked) {
int[] usedNumbers = []
while (true) {
for(int i = 0; i < 8; i++) {
int newRandomNum = 0;
while(newRandomNum is not in usedNumbers) {
newRandomNum = radomNumberGenerator(0,8)
}
usedNumbers.append(newRandomNum)
if(Attacked[i][newRandomNum] == 1) {
break for loop
}
Board[i][newRandomNum) = 1
update Attacked Matrix
}
if(i == 8) {
return Board
}
clear Board Matrix
clear Attacked Matrix
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment