Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* sudoky.c :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: squiana <[email protected]> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2019/07/14 20:46:01 by squiana #+# #+# */
- /* Updated: 2019/07/14 21:17:56 by ckumera ### ########.fr */
- /* */
- /* ************************************************************************** */
- #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