norminetted backtrack.c and get_cur_pos.c
This commit is contained in:
parent
d340b998cb
commit
226e625e16
|
@ -1,4 +1,14 @@
|
|||
#include <stdio.h>
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* backtrack.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: smatthes <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/26 22:44:15 by smatthes #+# #+# */
|
||||
/* Updated: 2023/03/26 22:47:19 by smatthes ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int is_valid_state(int **board, int *borders, int *pos, int n);
|
||||
void get_cur_pos(int **board, int *pos, int n);
|
||||
|
@ -7,14 +17,17 @@ void print_board(int **board, int n);
|
|||
int backtrack(int **board, int *borders, int rec_depth, int n)
|
||||
{
|
||||
int pos[2];
|
||||
int y;
|
||||
int x;
|
||||
int counter;
|
||||
|
||||
get_cur_pos(board, pos, n);
|
||||
int y = pos[0];
|
||||
int x = pos[1];
|
||||
y = pos[0];
|
||||
x = pos[1];
|
||||
if (rec_depth == n * n)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
int counter = 0;
|
||||
while (++counter < n + 1)
|
||||
{
|
||||
board[y][x] = counter;
|
||||
|
|
|
@ -6,16 +6,17 @@
|
|||
/* By: smatthes <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/26 21:56:39 by smatthes #+# #+# */
|
||||
/* Updated: 2023/03/26 21:56:44 by smatthes ### ########.fr */
|
||||
/* Updated: 2023/03/26 22:49:45 by smatthes ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void get_cur_pos(int **board, int *pos, int n)
|
||||
{
|
||||
int i = -1;
|
||||
int j = -1;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = -1;
|
||||
j = -1;
|
||||
while (++i < n)
|
||||
{
|
||||
while (++j < n)
|
||||
|
|
Loading…
Reference in New Issue