Advertisement
rihardmarius

producto cartesiano de grupos

Aug 28th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <array>
  3. using namespace std;
  4.  
  5. /* *1 | 0 1 2       *2 | a b
  6.    ---+-------      ---+-----
  7.     0 | 0 1 2        a | a b
  8.     1 | 1 2 0        b | b a
  9.     2 | 2 0 1
  10. */
  11.  
  12. struct coord {
  13.     int a;
  14.     char b;
  15. };
  16.  
  17. int op1 (int a, int b);
  18. char op2 (char a, char b);
  19. coord op12 (coord a, coord b);
  20. bool comprobar_asociatividad(array<coord,6> arr2);
  21. void verificar_simetria (array<array<coord,6>,6>& a);
  22.  
  23. int main()
  24. {
  25.     array<array<coord,6>,6> arr1;
  26.     array<coord,6> arr2 = {0,'a',0,'b',1,'a',1,'b',2,'a',2,'b'};
  27.  
  28.     for (int i=0; i<6; i++) //fills and prints matrix
  29.     {
  30.         for (int j=0; j<6; j++)
  31.         {
  32.             arr1.at(i).at(j) = op12(arr2.at(i),arr2.at(j));
  33.             cout << arr1.at(i).at(j).a << arr1.at(i).at(j).b << ' ';
  34.         }
  35.         cout << endl;
  36.     }
  37.     cout << endl;
  38.  
  39.     verificar_simetria(arr1);
  40.  
  41.     if (comprobar_asociatividad(arr2))
  42.         cout << "Asociativa: si" << endl << endl;
  43.     else
  44.         cout << "Asociativa: no" << endl << endl;
  45.  
  46.     return 0;
  47. }
  48.  
  49. void verificar_simetria (array<array<coord,6>,6>& a)
  50. {
  51.     for (int i=0; i<6; i++)
  52.         for (int j=0; j<6; j++)
  53.             if (a.at(i).at(j).a != a.at(j).at(i).a or a.at(i).at(j).b != a.at(j).at(i).b)
  54.             {
  55.                 cout << "Simetrica: no\n";
  56.                 return;
  57.             }
  58.     cout << "Simetrica: si\n";
  59. }
  60.  
  61. bool comprobar_asociatividad(array<coord,6> arr2)
  62. {
  63.     coord miembro1, miembro2;
  64.     for (int i=0; i<6; i++)
  65.         for (int j=0; j<6; j++)
  66.             for (int k=0; k<6; k++)
  67.             {
  68.                 miembro1 = op12(arr2.at(i),op12(arr2.at(j),arr2.at(k)));
  69.                 miembro2 = op12(op12(arr2.at(i),arr2.at(j)),arr2.at(k));
  70.                 if (miembro1.a != miembro2.a or miembro1.b != miembro2.b)
  71.                     return false;
  72.             }
  73.     return true;
  74. }
  75.  
  76. coord op12 (coord p, coord r)
  77. {
  78.     return {op1(p.a,r.a),op2(p.b,r.b)};
  79. }
  80.  
  81. int op1 (int a, int b)
  82. {
  83.     return (a+b)%3;
  84. }
  85.  
  86. char op2 (char a, char b)
  87. {
  88.     if(a=='a' and b=='a' or a=='b' and b=='b')
  89.         return 'a';
  90.     if(a=='a' and b=='b' or a=='b' and b=='a')
  91.         return 'b';
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement