rm tmp
This commit is contained in:
parent
faaa653c17
commit
ef055f0456
|
@ -1,70 +0,0 @@
|
|||
#include "helpers.h"
|
||||
#include "backtrack.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int is_solved(int board[SIZE][SIZE])
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
while (i < SIZE)
|
||||
{
|
||||
j = 0;
|
||||
while (j < SIZE)
|
||||
{
|
||||
if (!board[i][j])
|
||||
return (0);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int next_cell_pos(int board[SIZE][SIZE])
|
||||
{
|
||||
int pos;
|
||||
|
||||
pos = 0;
|
||||
while (board[pos / SIZE][pos % SIZE])
|
||||
pos++;
|
||||
return (pos);
|
||||
}
|
||||
|
||||
void *get_candidates(int board[SIZE][SIZE], int next_cell)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
int backtrack(int board[SIZE][SIZE], int clues[SIZE * 4])
|
||||
{
|
||||
int next_cell;
|
||||
void *candidates;
|
||||
|
||||
if (is_solved(board))
|
||||
return (1);
|
||||
next_cell = next_cell_pos(board);
|
||||
candidates = get_candidates(board, next_cell);
|
||||
printf("%d\n", candidates[0];
|
||||
return (0);
|
||||
}
|
||||
|
||||
void print_board(int board[SIZE][SIZE])
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = -1;
|
||||
while (++i < SIZE)
|
||||
{
|
||||
j = -1;
|
||||
while (++j < SIZE)
|
||||
{
|
||||
ft_putchar(board[i][j] + '0');
|
||||
ft_putchar(' ');
|
||||
}
|
||||
ft_putchar('\b');
|
||||
ft_putchar('\n');
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
#ifndef BACKTRACK_H
|
||||
# define BACKTRACK_H
|
||||
|
||||
int backtrack(int board[SIZE][SIZE], int clues[SIZE]);
|
||||
void print_board(int board[SIZE][SIZE]);
|
||||
|
||||
#endif
|
|
@ -1,25 +0,0 @@
|
|||
#include "helpers.h"
|
||||
|
||||
int is_valid_input(int argc, char **argv)
|
||||
{
|
||||
char *input;
|
||||
int valid_input_len;
|
||||
int i;
|
||||
|
||||
if (argc != 2)
|
||||
return (0);
|
||||
input = argv[1];
|
||||
valid_input_len = SIZE * 4 * 2 - 1;
|
||||
if (ft_strlen(input) != valid_input_len)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (i < valid_input_len)
|
||||
{
|
||||
if (i % 2 == 0 && (input[i] < '1' || input[i] > '4'))
|
||||
return (0);
|
||||
if (i % 2 == 1 && input[i] != ' ')
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
#ifndef ERROR_CHECK_H
|
||||
# define ERROR_CHECK_H
|
||||
# include "helpers.h"
|
||||
|
||||
int is_valid_input(int argc, char **argv);
|
||||
|
||||
#endif
|
|
@ -1,67 +0,0 @@
|
|||
#include <unistd.h>
|
||||
#include "helpers.h"
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
|
||||
void init_board(int board[SIZE][SIZE])
|
||||
{
|
||||
// int i;
|
||||
// int j;
|
||||
|
||||
// i = -1;
|
||||
// while (++i < SIZE)
|
||||
// {
|
||||
// j = -1;
|
||||
// while (++j < SIZE)
|
||||
// board[i][j] = 0;
|
||||
// }
|
||||
board[0][0] = 1;
|
||||
board[0][1] = 2;
|
||||
board[0][2] = 3;
|
||||
board[0][3] = 4;
|
||||
board[1][0] = 2;
|
||||
board[1][1] = 3;
|
||||
board[1][2] = 4;
|
||||
board[1][3] = 1;
|
||||
board[2][0] = 3;
|
||||
board[2][1] = 4;
|
||||
board[2][2] = 1;
|
||||
board[2][3] = 2;
|
||||
board[3][0] = 4;
|
||||
board[3][1] = 1;
|
||||
board[3][2] = 2;
|
||||
board[3][3] = 3;
|
||||
board[3][3] = 0;
|
||||
}
|
||||
|
||||
int ft_puterr(int exit_code)
|
||||
{
|
||||
write(1, "Error\n", 6);
|
||||
return (exit_code);
|
||||
}
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
void get_clues(char *input, int *border)
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
|
||||
len = ft_strlen(input);
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
*border++ = input[i] - '0';
|
||||
i += 2;
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#ifndef HELPERS_H
|
||||
# define HELPERS_H
|
||||
# define SIZE 4
|
||||
|
||||
void ft_putchar(char c);
|
||||
int ft_strlen(char *str);
|
||||
int ft_puterr(int exit_code);
|
||||
void init_board(int board[SIZE][SIZE]);
|
||||
void get_clues(char *input, int *border);
|
||||
|
||||
#endif
|
||||
|
18
tmp/main.c
18
tmp/main.c
|
@ -1,18 +0,0 @@
|
|||
#include "helpers.h"
|
||||
#include "error_check.h"
|
||||
#include "backtrack.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int board[SIZE][SIZE];
|
||||
int clues[SIZE * 4];
|
||||
|
||||
if (!is_valid_input(argc, argv))
|
||||
return (ft_puterr(1));
|
||||
get_clues(argv[1], clues);
|
||||
init_board(board);
|
||||
if (!backtrack(board, clues))
|
||||
return (ft_puterr(2));
|
||||
print_board(board);
|
||||
return (0);
|
||||
}
|
Loading…
Reference in New Issue