Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- int test_symbol(int n, char **tab);
- int sudoky(int place, char **tab);
- void display(char **tab);
- int main(int argc, char **argv)
- {
- if (test_symbol(argc, argv))
- {
- if (sudoky(9, argv))
- display(argv);
- else
- write(1, "Error\n", 6);
- }
- else
- write(1, "Error\n", 6);
- return (0);
- }
- =================================================
- #include <unistd.h>
- int test_line(char **tab, char nb, int i);
- int test_column(char **tab, char nb, int j);
- int test_block(char **tab, int i, int j, char nb);
- void ft_putchar(char c)
- {
- write(1, &c, 1);
- }
- void display(char **tab)
- {
- int i;
- int j;
- i = 1;
- while (i <= 9)
- {
- j = 0;
- while (tab[i][j] != '\0')
- {
- ft_putchar(tab[i][j]);
- if (j != 8)
- ft_putchar(' ');
- j++;
- }
- ft_putchar('\n');
- i++;
- }
- }
- int sudoky(int place, char **tab)
- {
- int i;
- int j;
- char nb;
- nb = '0';
- i = place / 9;
- j = place % 9;
- if (place == 90)
- return (1);
- if (tab[i][j] != '.')
- return (sudoky(place + 1, tab));
- while (++nb <= '9')
- {
- if (test_line(tab, nb, i) + test_column(tab, nb, j) + test_block(tab, i, j, nb) == 3)
- {
- tab[i][j] = nb;
- if (sudoky(place + 1, tab))
- return (1);
- }
- }
- tab[i][j] = '.';
- return (0);
- }
- =======================================
- #include <unistd.h>
- int test_line(char **tab, char nb, int i);
- int test_column(char **tab, char nb, int j);
- int test_block(char **tab, int i, int j, char nb);
- void ft_putchar(char c)
- {
- write(1, &c, 1);
- }
- void display(char **tab)
- {
- int i;
- int j;
- i = 1;
- while (i <= 9)
- {
- j = 0;
- while (tab[i][j] != '\0')
- {
- ft_putchar(tab[i][j]);
- if (j != 8)
- ft_putchar(' ');
- j++;
- }
- ft_putchar('\n');
- i++;
- }
- }
- int sudoky(int place, char **tab)
- {
- int i;
- int j;
- char nb;
- nb = '0';
- i = place / 9;
- j = place % 9;
- if (place == 90)
- return (1);
- if (tab[i][j] != '.')
- return (sudoky(place + 1, tab));
- while (++nb <= '9')
- {
- if (test_line(tab, nb, i) + test_column(tab, nb, j) + test_block(tab, i, j, nb) == 3)
- {
- tab[i][j] = nb;
- if (sudoky(place + 1, tab))
- return (1);
- }
- }
- tab[i][j] = '.';
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment