IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

probleme de permutation des colonnes d'un tableau !?


Sujet :

C

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    126
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 126
    Points : 70
    Points
    70
    Par défaut probleme de permutation des colonnes d'un tableau !?
    Bonjour,
    Voici mon probleme je voudrais essayer de générer une grille de sudoku cependant j'ai un début d'idée mais quelques soucis d'application !
    Voilà je souhaiterais partir d'une grille déja existante et me contenter de permuter aléatoirement les colonnes puis les lignes de façon a vérifier toujours les régles du sudoku !

    Ici j'ai essayer de faire un test sur la permutation des 3 premières colonnes.
    voici ce que j'ai coder :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
     
    int solution [9][9]={{6,2,1,3,7,8,4,9,5},
                         {7,8,3,5,9,4,6,1,2},
                         {5,4,9,2,6,1,8,3,7},
                         {1,6,4,7,5,9,2,8,3},
                         {3,7,8,4,2,6,9,5,1},
                         {9,5,2,8,1,3,7,6,4},
                         {2,9,6,1,3,7,5,4,8},
                         {4,1,5,9,8,2,3,7,6},
                         {8,3,7,6,4,5,1,2,9}};
     
    int permutation [9][9]={};
    double N,N2;
    int N1,N3;
    srand(time(0));
     
    N=0;           
      do
      {
      N=((double)(rand())/(double)(RAND_MAX));
      N1=N+1;
      printf("%i",N1);
      N2=((double)(rand())/(double)(RAND_MAX));
      N3=N2+1;
      printf("%i",N3);
      }while(N1==N3);
    // PERMUTATION COLONNE
     
      for(J=0;J<9;J++)
      {
      for(I=0;I<9;I++)
      {
     
      permutation[I][J]=solution[I][N1];
      solution[I][N1]=solution[I][N2];
      solution[I][N2]=permutation[I][J];
      }
      }
     
     
     
    printf("     0    1    2     3    4    5     6    7    8\n  ");
    printf("   ^    ^    ^     ^    ^    ^     ^    ^    ^\n    ");
    printf(" ^    ^    ^     ^    ^    ^     ^    ^    ^\n    ");
    printf("\n");
     
     
    for(I=0;I<=8;I++)
    {
    printf("%i>>",I);
    	for(J=0;J<=8;J++)
    	{
            if(solution[I][J]==0)
            Color(12,0);
    		printf("%3d  ",solution[I][J]);
    		Color(15,0);
    		if(J==2 || J==5) printf("|");
    	}
    printf("\n");
     
    if(I==2 || I==5)
     
    printf("  \n     ===========================================");printf("\n"); printf("\n");
     
    }
     
     
    system("pause");
    comme vous l'aurez remarquez en compilant j'ai un probléme de compatibilité au niveau des types il doit y avoir un conflit de type entre le double et le int mais je ne voit pas comment le résoudre ?

    Pourriez vous me dire également si je part dans un cul de sac ou est ce une solution envisageable ???

    Merci d'avance
    Masterix

  2. #2
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par masterix59
    voici ce que j'ai coder :
    comme vous l'aurez remarquez en compilant j'ai un probléme de compatibilité au niveau des types il doit y avoir un conflit de type entre le double et le int mais je ne voit pas comment le résoudre ?
    Faut peut être pas exagérer non plus...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    Project   : Forums
    Compiler  : GNU GCC Compiler (called directly)
    Directory : C:\dev\forums2\
    --------------------------------------------------------------------------------
    Switching to target: default
    Compiling: main.c
    main.c:14: error: syntax error before '(' token
    main.c:16: warning: type defaults to `int' in declaration of `N'
    main.c:16: error: conflicting types for 'N'
    main.c:12: error: previous declaration of 'N' was here
    main.c:16: warning: data definition has no type or storage class
    main.c:17: error: syntax error before "do"
    main.c:20: warning: type defaults to `int' in declaration of `N1'
    main.c:20: error: initializer element is not constant
    main.c:20: warning: data definition has no type or storage class
    main.c:21: error: syntax error before string constant
    main.c:21: warning: type defaults to `int' in declaration of `printf'
    main.c:21: warning: function declaration isn't a prototype
    main.c:21: warning: conflicting types for built-in function 'printf'
    main.c:21: warning: data definition has no type or storage class
    main.c:22: warning: type defaults to `int' in declaration of `N2'
    main.c:22: error: conflicting types for 'N2'
    main.c:12: error: previous declaration of 'N2' was here
    main.c:22: warning: implicit declaration of function `rand'
    main.c:22: error: `RAND_MAX' undeclared here (not in a function)
    main.c:22: warning: data definition has no type or storage class
    main.c:23: warning: type defaults to `int' in declaration of `N3'
    main.c:23: error: initializer element is not constant
    main.c:23: warning: data definition has no type or storage class
    main.c:24: error: syntax error before string constant
    main.c:24: warning: type defaults to `int' in declaration of `printf'
    main.c:24: warning: function declaration isn't a prototype
    main.c:24: warning: data definition has no type or storage class
    main.c:34: error: `I' undeclared here (not in a function)
    main.c:34: warning: type defaults to `int' in declaration of `solution'
    main.c:34: error: variable-size type declared outside of any function
    main.c:34: warning: data definition has no type or storage class
    main.c:35: warning: type defaults to `int' in declaration of `solution'
    main.c:35: error: variable-size type declared outside of any function
    main.c:35: error: `J' undeclared here (not in a function)
    main.c:35: warning: data definition has no type or storage class
    main.c:36: error: syntax error before '}' token
    main.c:41: error: syntax error before string constant
    main.c:41: warning: type defaults to `int' in declaration of `printf'
    main.c:41: warning: function declaration isn't a prototype
    main.c:41: warning: data definition has no type or storage class
    main.c:42: error: syntax error before string constant
    main.c:42: warning: type defaults to `int' in declaration of `printf'
    main.c:42: warning: function declaration isn't a prototype
    main.c:42: warning: data definition has no type or storage class
    main.c:43: error: syntax error before string constant
    main.c:43: warning: type defaults to `int' in declaration of `printf'
    main.c:43: warning: function declaration isn't a prototype
    main.c:43: warning: data definition has no type or storage class
    main.c:44: error: syntax error before string constant
    main.c:44: warning: type defaults to `int' in declaration of `printf'
    main.c:44: warning: function declaration isn't a prototype
    main.c:44: warning: data definition has no type or storage class
    main.c:54: error: syntax error before string constant
    main.c:54: warning: type defaults to `int' in declaration of `printf'
    main.c:54: warning: function declaration isn't a prototype
    main.c:54: warning: data definition has no type or storage class
    main.c:55: error: syntax error before numeric constant
    main.c:55: warning: type defaults to `int' in declaration of `Color'
    main.c:55: warning: function declaration isn't a prototype
    main.c:55: warning: data definition has no type or storage class
    main.c:58: error: syntax error before string constant
    main.c:58: warning: type defaults to `int' in declaration of `printf'
    main.c:58: warning: function declaration isn't a prototype
    main.c:58: warning: data definition has no type or storage class
    main.c:62: error: syntax error before string constant
    main.c:62: warning: type defaults to `int' in declaration of `printf'
    main.c:62: warning: function declaration isn't a prototype
    main.c:62: warning: data definition has no type or storage class
    main.c:62: error: syntax error before string constant
    main.c:62: warning: type defaults to `int' in declaration of `printf'
    main.c:62: warning: function declaration isn't a prototype
    main.c:62: warning: data definition has no type or storage class
    main.c:67: error: syntax error before string constant
    main.c:67: warning: type defaults to `int' in declaration of `system'
    main.c:67: warning: function declaration isn't a prototype
    main.c:67: warning: data definition has no type or storage class
    main.c:67:17: warning: no newline at end of file
    Process terminated with status 1 (0 minutes, 5 seconds)
    26 errors, 51 warnings
    Il faut apprendre à isoler les problèmes et à les traiter un par un... et surtout à ne pas poster du code incomplet...

    Ceci marchouille...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
     
    #include <stdlib.h>
    #include <time.h>
    #include <stdio.h>
     
    int main (void)
    {
       int solution[9][9] = {
          {6, 2, 1, 3, 7, 8, 4, 9, 5},
          {7, 8, 3, 5, 9, 4, 6, 1, 2},
          {5, 4, 9, 2, 6, 1, 8, 3, 7},
          {1, 6, 4, 7, 5, 9, 2, 8, 3},
          {3, 7, 8, 4, 2, 6, 9, 5, 1},
          {9, 5, 2, 8, 1, 3, 7, 6, 4},
          {2, 9, 6, 1, 3, 7, 5, 4, 8},
          {4, 1, 5, 9, 8, 2, 3, 7, 6},
          {8, 3, 7, 6, 4, 5, 1, 2, 9}
       };
     
       int permutation[9][9] = { 0 };
       int N1, N2;
       int I, J;
       srand (time (NULL));
     
    /* un coup pour rien (toujours 1) */
       rand ();
     
       N1 = rand () % 2;
       printf ("%d: ", N1);
       do
       {
          N2 = N1 + rand () % 2;
          printf ("%2d", N2);
       }
       while (N1 == N2);
       printf ("\n");
    // PERMUTATION COLONNE
     
       for (J = 0; J < 9; J++)
       {
          for (I = 0; I < 9; I++)
          {
     
             permutation[I][J] = solution[I][N1];
             solution[I][N1] = solution[I][N2];
             solution[I][N2] = permutation[I][J];
          }
       }
     
       printf ("     0    1    2     3    4    5     6    7    8\n");
       printf ("     v    v    v     v    v    v     v    v    v\n");
       printf ("     v    v    v     v    v    v     v    v    v\n");
     
       for (I = 0; I <= 8; I++)
       {
          printf ("%i>>", I);
          for (J = 0; J <= 8; J++)
          {
             if (solution[I][J] == 0)
             {
                printf ("     ");
             }
             else
             {
                printf ("%3d  ", solution[I][J]);
             }
             if (J == 2 || J == 5)
                printf ("|");
          }
          printf ("\n");
     
          if (I == 2 || I == 5)
     
             printf ("     ===========================================\n");
       }
     
       return 0;
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    1:  1 2
         0    1    2     3    4    5     6    7    8
         v    v    v     v    v    v     v    v    v
         v    v    v     v    v    v     v    v    v
    0>>  6    1    2  |  3    7    8  |  4    9    5
    1>>  7    3    8  |  5    9    4  |  6    1    2
    2>>  5    9    4  |  2    6    1  |  8    3    7
         ===========================================
    3>>  1    4    6  |  7    5    9  |  2    8    3
    4>>  3    8    7  |  4    2    6  |  9    5    1
    5>>  9    2    5  |  8    1    3  |  7    6    4
         ===========================================
    6>>  2    6    9  |  1    3    7  |  5    4    8
    7>>  4    5    1  |  9    8    2  |  3    7    6
    8>>  8    7    3  |  6    4    5  |  1    2    9
     
    Press ENTER to continue.

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    126
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 126
    Points : 70
    Points
    70
    Par défaut
    petite erreur il est vrai dsl j'avais fait un copier coller trop rapidement !

    Merci beaucoup pour ces petit réctificatif !!!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 14/11/2006, 10h45
  2. [HTML] Dimensionnement des colonnes d'un tableau
    Par cchampion2fr dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 09/11/2006, 16h04
  3. Réponses: 7
    Dernier message: 22/09/2006, 15h52
  4. Masquer des colonnes dans un tableau
    Par fornorst dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 26/04/2006, 21h00
  5. En-tête d'un des colonnes d'un tableau
    Par Mvu dans le forum ASP
    Réponses: 2
    Dernier message: 06/05/2004, 17h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo