Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cassert>
- #include <stdlib.h>
- using namespace std ;
- class Cellular {
- private :
- int Regula ;
- char *RegulaLancuchBin ;
- public :
- Cellular() {
- RegulaLancuchBin=new char [ 8 ] ;
- if ( ! RegulaLancuchBin ){
- cout<<"brak pamieci dla tablicy RegulaLancuchBin[8]"<<endl ;
- }
- }
- void WczytajRegule ( int dec ){
- assert ( dec>=0 && dec <256);
- Regula=dec ;
- i_to_s (Regula , RegulaLancuchBin , 2 , 8 ) ;
- };
- void i_to_s ( int xx , char * lanc , int nn , int DLUG) ;
- void PokazRegule() {
- cout<<"Regula "<<Regula<<": "<<RegulaLancuchBin<<endl ;
- }
- int ZakodujSasiedztwo ( const int &lewy , const int &srodek , const int &prawy ){
- int liczba_dekod , reg , ref ;
- char znak , zero='0';
- ref=(int ) zero ;
- reg=prawy+2*srodek+4*lewy ;
- znak=*(RegulaLancuchBin+7-reg ) ;
- liczba_dekod =(( int ) ( znak))- ref ;
- return liczba_dekod ;
- }
- };
- void Cellular :: i_to_s ( int xx , char * lanc , int nn , int DLUG){
- long x=xx ;
- int l=DLUG-1;
- long n = nn ;
- int j ;
- for ( j =0; j<DLUG; j++) *( lanc+j )='0' ;
- *( lanc+DLUG)='0' ;
- if ( ! x ) ;
- else
- {
- do
- {
- *( lanc+l )='0'+x % n ;
- x/=n ;
- l --;
- } while ( x ) ;
- for ( j =0; j<l ; j++) *( lanc+j )='0' ;
- *( lanc+DLUG)='0' ;
- }
- }
- void WarunkiPeriodyczne ( int &i_left , const int &i , int &i_right , const int &L ) ;
- int main ( int argc , char ** argv ){
- if ( argc !=4){
- cout<<"Poprawny format polecenia: " ;
- cout<<argv [0]<<" nr˙reg˙Wolframa l˙krok˙czas l˙wezlow"<<endl ;
- return 0 ;
- }
- int reg=atoi ( argv [ 1 ] ) ;
- int T=atoi ( argv [ 2 ] ) ;
- int L=atoi ( argv [ 3 ] ) ;
- Cellular A;
- A.WczytajRegule ( reg ) ;
- A. PokazRegule ( ) ;
- int *Dywan=new int [L ] ;
- int *DD=new int [L ] ;
- for ( int i =0; i<L; i++){
- Dywan [ i ]=0;
- }
- int ilewy , isrod , iprawy ;
- int slewy , ssrod , sprawy ;
- *(Dywan+L/2)=1; // s t a r t
- for ( int t=0; t<T; t++){
- for ( int i =0; i<L; i++){
- if ( * (Dywan+i )==1)cout<<"*" ; else cout<<" " ;
- }
- cout<<endl ;
- for ( int i =0; i<L; i++){
- ilewy=i -1; isrod=i ; iprawy=i +1;
- WarunkiPeriodyczne ( ilewy , isrod , iprawy ,L ) ;
- slewy=*(Dywan+ilewy ) ; ssrod=*(Dywan+isrod ) ; sprawy=*(Dywan+iprawy ) ;
- *(DD+i )=A. ZakodujSasiedztwo ( slewy , ssrod , sprawy ) ;
- }
- for ( int i =0; i<L; i++){
- *(Dywan+i )=*(DD+i ) ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement