eg0rmaffin

final_version_rush01

Jul 14th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.20 KB | None | 0 0
  1. #include <unistd.h>
  2.  
  3. int     test_symbol(int n, char **tab);
  4. int     sudoky(int place, char **tab);
  5. void    display(char **tab);
  6.  
  7. int     main(int argc, char **argv)
  8. {
  9.     if (test_symbol(argc, argv))
  10.     {
  11.         if (sudoky(9, argv))
  12.             display(argv);
  13.         else
  14.             write(1, "Error\n", 6);
  15.     }
  16.     else
  17.         write(1, "Error\n", 6);
  18.     return (0);
  19. }
  20.  
  21. =================================================
  22.  
  23. #include <unistd.h>
  24.  
  25. int     test_line(char **tab, char nb, int i);
  26. int     test_column(char **tab, char nb, int j);
  27. int     test_block(char **tab, int i, int j, char nb);
  28.  
  29. void    ft_putchar(char c)
  30. {
  31.     write(1, &c, 1);
  32. }
  33.  
  34. void    display(char **tab)
  35. {
  36.     int i;
  37.     int j;
  38.  
  39.     i = 1;
  40.     while (i <= 9)
  41.     {
  42.         j = 0;
  43.         while (tab[i][j] != '\0')
  44.         {
  45.             ft_putchar(tab[i][j]);
  46.             if (j != 8)
  47.                 ft_putchar(' ');
  48.             j++;
  49.         }
  50.         ft_putchar('\n');
  51.         i++;
  52.     }
  53. }
  54. int sudoky(int place, char **tab)
  55. {
  56.     int     i;
  57.     int     j;
  58.     char    nb;
  59.  
  60.     nb = '0';
  61.     i = place / 9;
  62.     j = place % 9;
  63.     if (place == 90)
  64.         return (1);
  65.     if (tab[i][j] != '.')
  66.         return (sudoky(place + 1, tab));
  67.     while (++nb <= '9')
  68.     {
  69.         if (test_line(tab, nb, i) + test_column(tab, nb, j) + test_block(tab, i, j, nb) == 3)
  70.         {
  71.             tab[i][j] = nb;
  72.             if (sudoky(place + 1, tab))
  73.                 return (1);
  74.         }
  75.     }
  76.     tab[i][j] = '.';
  77.     return (0);
  78. }
  79.  
  80. =======================================
  81.  
  82. #include <unistd.h>
  83.  
  84. int     test_line(char **tab, char nb, int i);
  85. int     test_column(char **tab, char nb, int j);
  86. int     test_block(char **tab, int i, int j, char nb);
  87.  
  88. void    ft_putchar(char c)
  89. {
  90.     write(1, &c, 1);
  91. }
  92.  
  93. void    display(char **tab)
  94. {
  95.     int i;
  96.     int j;
  97.  
  98.     i = 1;
  99.     while (i <= 9)
  100.     {
  101.         j = 0;
  102.         while (tab[i][j] != '\0')
  103.         {
  104.             ft_putchar(tab[i][j]);
  105.             if (j != 8)
  106.                 ft_putchar(' ');
  107.             j++;
  108.         }
  109.         ft_putchar('\n');
  110.         i++;
  111.     }
  112. }
  113. int sudoky(int place, char **tab)
  114. {
  115.     int     i;
  116.     int     j;
  117.     char    nb;
  118.  
  119.     nb = '0';
  120.     i = place / 9;
  121.     j = place % 9;
  122.     if (place == 90)
  123.         return (1);
  124.     if (tab[i][j] != '.')
  125.         return (sudoky(place + 1, tab));
  126.     while (++nb <= '9')
  127.     {
  128.         if (test_line(tab, nb, i) + test_column(tab, nb, j) + test_block(tab, i, j, nb) == 3)
  129.         {
  130.             tab[i][j] = nb;
  131.             if (sudoky(place + 1, tab))
  132.                 return (1);
  133.         }
  134.     }
  135.     tab[i][j] = '.';
  136.     return (0);
  137. }
Advertisement
Add Comment
Please, Sign In to add comment