Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cassert>
- #include <stdlib.h>
- #include <vector>
- using namespace std;
- void FixValues(int &ileft, int &i, int &iright);
- int DecodeValue(int &left, int &middle, int &right);
- void MakeBinary(int dec);
- int RULE;
- char *RULE_BINARY;
- int TIME_Q;
- int NUMBER_OF_ITERATIONS;
- int main(int argc, char ** argv)
- {
- cout << "Podaj numer reguly wolframa: ";
- cin >> RULE;
- cout << endl;
- cout << "Podaj liczbe krokow czasowych: ";
- cin >> TIME_Q;
- cout << endl;
- cout << "Podaj liczbe wezlow: ";
- cin >> NUMBER_OF_ITERATIONS;
- cout << endl;
- MakeBinary(RULE);
- int *READONLY_TAB = new int[NUMBER_OF_ITERATIONS];
- int *OUTPUT_TAB = new int[NUMBER_OF_ITERATIONS];
- //wektor użyty w formie list, zawierający wszystkie przebiegi
- vector<bool> FULL_TAB;
- for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
- READONLY_TAB[i] = 0;
- }
- int ilewy, isrod, iprawy;
- READONLY_TAB[NUMBER_OF_ITERATIONS / 2] = 1;
- for (int t = 0; t < TIME_Q; t++)
- {
- //wyrysowanie wiersza automatów
- for (int i = 0; i < NUMBER_OF_ITERATIONS; i++)
- {
- if (READONLY_TAB[i] == 1)
- {
- //zapisanie i wyświetlenie wartości
- FULL_TAB.push_back(false);
- cout << "#";
- }
- else
- {
- //zapisanie i wyświetlenie wartości
- FULL_TAB.push_back(true);
- cout << " ";
- }
- }
- cout << endl;
- //wyliczenie kolejnego wiersza wyników automatu
- for (int i = 0; i < NUMBER_OF_ITERATIONS; i++)
- {
- ilewy = i - 1;
- isrod = i;
- iprawy = i + 1;
- FixValues(ilewy, isrod, iprawy);
- //zapisanie wartości do pomocniczej tabeli
- OUTPUT_TAB[i] = DecodeValue(READONLY_TAB[ilewy], READONLY_TAB[isrod], READONLY_TAB[iprawy]);
- }
- //skopiowanie wartości do właściwej tabeli
- for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
- READONLY_TAB[i] = OUTPUT_TAB[i];
- }
- }
- system("pause");
- return 0;
- }
- void FixValues(int &ilewy, int &i, int &iprawy) {
- if (i == 0) {
- ilewy = NUMBER_OF_ITERATIONS - 1;
- }
- else if (i == NUMBER_OF_ITERATIONS - 1)
- {
- iprawy = 0;
- }
- }
- void MakeBinary(int dec)
- { RULE_BINARY = new char[8];
- assert(dec >= 0 && dec < 256);
- RULE = dec;
- long x = RULE;
- long n = 2;
- for (int j = 0; j <= 8; j++). {
- RULE_BINARY[j] = '0';
- }
- if (x)
- {
- int l = 7;
- for (;l >= 0;l--, x /= n)
- {
- RULE_BINARY[l] = '0' + x % n;
- }
- for (int j = 0; j <= l; j++)
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement