Skip to content

Instantly share code, notes, and snippets.

@LeReverandNox
Created October 17, 2018 19:45
Show Gist options
  • Select an option

  • Save LeReverandNox/652a52b06f805290418af537fe00a011 to your computer and use it in GitHub Desktop.

Select an option

Save LeReverandNox/652a52b06f805290418af537fe00a011 to your computer and use it in GitHub Desktop.
int recurse_n_queen(int **grid, int n, int col)
{
int row;
int i;
int j;
int as_cycle;
if (col >= n)
return 1;
row = (rand() % n);
j = row;
i = n;
as_cycle = 0;
printf("On va boucler a partir de %d\n", row);
while (row < i)
{
if (is_placement_possible(grid, n, row, col))
{
grid[row][col] = 1;
if (recurse_n_queen(grid, n, col +1))
return 1;
grid[row][col] = 0;
}
printf("row: %d\n", row);
row += 1;
if (row == i && !as_cycle)
{
as_cycle = 1;
row = 0;
i = j;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment