Noam_15

הבית עם האיקס - כל הפתרונות

Jun 12th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. void the_big_to_the_first(int &n1, int &n2){
  6.     if(n1<n2){
  7.         int tmp = n1;
  8.         n1 = n2;
  9.         n2 = tmp;
  10.     }
  11. }
  12.  
  13.  
  14. class HomeArray{
  15. public:
  16.     int arr[9];
  17.  
  18.  
  19.     void set(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9){
  20.         arr[0] = n1;
  21.         arr[1] = n2;
  22.         arr[2] = n3;
  23.         arr[3] = n4;
  24.         arr[4] = n5;
  25.         arr[5] = n6;
  26.         arr[6] = n7;
  27.         arr[7] = n8;
  28.         arr[8] = n9;
  29.     }
  30.     void show(){
  31.         for (int i=0; i<9; i++) cout<<arr[i]<<" ";
  32.         cout<<"\n";
  33.     }
  34.  
  35.     void show_full(){
  36.        
  37.  
  38.     }
  39.     bool is_it_legal(){
  40.         for (int i=0; i<8; i++){
  41.             if(arr[i]==arr[i+1]) return false;
  42.             switch (arr[i]){
  43.             case 0: if(arr[i+1]!=1 && arr[i+1]!=2){ return false;} break;
  44.             case 3: if(arr[i+1]==0){ return false;} break;
  45.             case 4: if(arr[i+1]==0){ return false;} break;
  46.             }
  47.             // עד כאן ווידאנו שיש קווים בצורה של הבית בלבד
  48.  
  49.  
  50.             // מכאן מתחילנ בדיקה שאין שני מקלות זהים
  51.             int an1 = arr[i], an2 = arr[i+1];
  52.             the_big_to_the_first(an1, an2);
  53.             // עד כאן המספר הגדול מבניהם נמצא במשתנה 1 והקטן במשתנה 2
  54.  
  55.             int ab1, ab2;
  56.             for(int j=i+1; j<8; j++){
  57.                 ab1 = arr[j], ab2 = arr[j+1];
  58.                 the_big_to_the_first(ab1, ab2);
  59.                 if(ab1==an1 && ab2==an2) return false;
  60.             }
  61.             // עד כאן הבדיקה
  62.  
  63.         }
  64.         return true;
  65.     }
  66. };
  67.  
  68.  
  69. void main(){
  70.     cout<<"\n   0\n  * *\n *   *\n1*****2\n*     *\n*     *\n3*****4\n\n\n";
  71.     cout<<"\n   0\n  * *\n *   *\n1*****2\n**   **\n* * * *\n*  *  *\n* * * *\n**   **\n3*****4\n";
  72.  
  73.     HomeArray HM[200], htmp;
  74.     int ind=0;
  75.     int i1, i2, i3, i4, i5, i6, i7, i8, i9;
  76.  
  77.     for(i1=0; i1<5; i1++){
  78.         for(i2=0; i2<5; i2++)
  79.             for(i3=0; i3<5; i3++)
  80.                 for(i4=0; i4<5; i4++)
  81.                     for(i5=0; i5<5; i5++)
  82.                         for(i6=0; i6<5; i6++)
  83.                             for(i7=0; i7<5; i7++)
  84.                                 for(i8=0; i8<5; i8++)
  85.                                     for(i9=0; i9<5; i9++){
  86.                                         htmp.set(i1, i2, i3, i4, i5, i6, i7, i8, i9);
  87.                                         if (htmp.is_it_legal() == true){
  88.                                             HM[ind] = htmp;
  89.                                             ind ++;
  90.                                         }
  91.                                     }
  92.     }
  93.     cout<<"\nThis program checks for all possible solutions to the game.\nFound: "<<ind<<"\n\n";
  94.     for(int i=0; i<ind; i++){
  95.         if(i<9)cout<<" ";
  96.         cout<<i+1<<"@      ";
  97.         HM[i].show();
  98.     }
  99.     cout<<"\n         -END-\n\n";
  100. }
Advertisement
Add Comment
Please, Sign In to add comment