Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <cassert>
  3. #include <stdlib.h>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. void FixValues(int &ileft, int &i, int &iright);
  9. int DecodeValue(int &left, int &middle, int &right);
  10. void MakeBinary(int dec);
  11.  
  12. int RULE;
  13. char *RULE_BINARY;
  14. int TIME_Q;
  15. int NUMBER_OF_ITERATIONS;
  16.  
  17. int main(int argc, char ** argv)
  18. {
  19.     cout << "Podaj numer reguly wolframa: ";
  20.     cin >> RULE;
  21.     cout << endl;
  22.     cout << "Podaj liczbe krokow czasowych: ";
  23.     cin >> TIME_Q;
  24.     cout << endl;
  25.     cout << "Podaj liczbe wezlow: ";
  26.     cin >> NUMBER_OF_ITERATIONS;
  27.     cout << endl;
  28.  
  29.     MakeBinary(RULE);
  30.  
  31.     int *READONLY_TAB = new int[NUMBER_OF_ITERATIONS];
  32.     int *OUTPUT_TAB = new int[NUMBER_OF_ITERATIONS];
  33.     //wektor użyty w formie list, zawierający wszystkie przebiegi
  34.     vector<bool> FULL_TAB;
  35.  
  36.     for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
  37.         READONLY_TAB[i] = 0;
  38.     }
  39.  
  40.     int ilewy, isrod, iprawy;
  41.  
  42.     READONLY_TAB[NUMBER_OF_ITERATIONS / 2] = 1;
  43.  
  44.     for (int t = 0; t < TIME_Q; t++)
  45.     {
  46.         //wyrysowanie wiersza automatów
  47.         for (int i = 0; i < NUMBER_OF_ITERATIONS; i++)
  48.         {
  49.             if (READONLY_TAB[i] == 1)
  50.             {
  51.                 //zapisanie i wyświetlenie wartości
  52.                 FULL_TAB.push_back(false);
  53.                 cout << "#";
  54.             }
  55.             else
  56.             {
  57.                 //zapisanie i wyświetlenie wartości
  58.                 FULL_TAB.push_back(true);
  59.                 cout << " ";
  60.             }
  61.         }
  62.         cout << endl;
  63.  
  64.         //wyliczenie kolejnego wiersza wyników automatu
  65.         for (int i = 0; i < NUMBER_OF_ITERATIONS; i++)
  66.         {
  67.             ilewy = i - 1;
  68.             isrod = i;
  69.             iprawy = i + 1;
  70.  
  71.             FixValues(ilewy, isrod, iprawy);
  72.  
  73.             //zapisanie wartości do pomocniczej tabeli
  74.             OUTPUT_TAB[i] = DecodeValue(READONLY_TAB[ilewy], READONLY_TAB[isrod], READONLY_TAB[iprawy]);
  75.         }
  76.  
  77.         //skopiowanie wartości do właściwej tabeli
  78.         for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
  79.             READONLY_TAB[i] = OUTPUT_TAB[i];
  80.         }
  81.     }
  82.  
  83.     system("pause");
  84.     return 0;
  85. }
  86.  
  87. void FixValues(int &ilewy, int &i, int &iprawy) {
  88.     if (i == 0)     {
  89.         ilewy = NUMBER_OF_ITERATIONS - 1;
  90.     }
  91.     else if (i == NUMBER_OF_ITERATIONS - 1)
  92.     {
  93.         iprawy = 0;
  94.     }
  95. }
  96.  
  97. void MakeBinary(int dec)
  98. {     RULE_BINARY = new char[8];
  99.  
  100.     assert(dec >= 0 && dec < 256);
  101.  
  102.     RULE = dec;
  103.  
  104.     long x = RULE;
  105.     long n = 2;
  106.  
  107.     for (int j = 0; j <= 8; j++).     {
  108.         RULE_BINARY[j] = '0';
  109.     }
  110.  
  111.     if (x)
  112.     {
  113.         int l = 7;
  114.         for (;l >= 0;l--, x /= n)
  115.         {
  116.             RULE_BINARY[l] = '0' + x % n;
  117.         }
  118.  
  119.         for (int j = 0; j <= l; j++)
  120.         {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement