daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Dec 14th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. std::vector<int> parseRule(std::string rule){
  5.     char x = rule[0];
  6.     int w = x-'0';
  7.     int d = 0;
  8.     if (rule[1]=='R'){
  9.         d = 1;
  10.     }
  11.     char y = rule[2];
  12.     int t = y-'0';
  13.     std::vector<int> v;
  14.     v.push_back(w);
  15.     v.push_back(d);
  16.     v.push_back(t);
  17.     return v;
  18. }
  19.  
  20. int main(int argc, char const *argv[])
  21. {
  22.     std::vector<int> machine;
  23.     machine.resize(2000020);
  24.     std::vector<std::vector<std::vector<int> > > states;
  25.     int n;
  26.     std::cin>>n;
  27.     std::vector<int> z;
  28.     std::vector<std::vector<int> > y;
  29.     y.push_back(z);
  30.     states.push_back(y);
  31.     for (int i = 0; i<n; i++){
  32.         std::string x;
  33.         std::cin>>x;
  34.         std::vector<int> rulea = parseRule(x);
  35.         std::string y;
  36.         std::cin>>y;
  37.         std::vector<int> ruleb = parseRule(y);
  38.         std::vector<std::vector<int> > rules;
  39.         rules.push_back(rulea);
  40.         rules.push_back(ruleb);
  41.         states.push_back(rules);
  42.     }
  43.     long iterations;
  44.     std::cin>>iterations;
  45.     /*for (std::vector<std::vector<int> > a : states){
  46.         std::cout<<"state"<<std::endl;
  47.         for (std::vector<int> b : a){
  48.             std::cout<<"case"<<std::endl;
  49.             for (int c : b){
  50.                 std::cout<<c<<std::endl;
  51.             }
  52.         }
  53.     }*/
  54.     long pointer = 1000010;
  55.     for (long h = 0; h<10; h++){
  56.         machine[pointer+h]=1;
  57.     }
  58.     for (long h = 11; h<20; h++){
  59.         machine[pointer+h]=1;
  60.     }
  61.     int state = 1;
  62.     for (long j = 0; j<iterations; j++){
  63.         for (long k = 1000010-30; k<1000010+40; k++){
  64.             std::cout<<machine[k];
  65.         }
  66.         std::cout<<std::endl;
  67.         if (state==0){
  68.             for (long k = 1000010-30; k<1000010+40; k++){
  69.                 std::cout<<machine[k];
  70.             }
  71.             std::cout<<std::endl<<j<<std::endl;
  72.             return 0;
  73.         }
  74.         int currentCell = machine[pointer];
  75.         int digitToWrite = states[state][currentCell][0];
  76.         int direction = states[state][currentCell][1];
  77.         int s = states[state][currentCell][2];
  78.         machine[pointer] = digitToWrite;
  79.         if (direction){
  80.             pointer++;
  81.         } else {
  82.             pointer--;
  83.         }
  84.         state = s;
  85.     }
  86.     for (long k = 1000010-3; k<1000010+4; k++){
  87.         std::cout<<machine[k];
  88.     }
  89.     std::cout<<std::endl<<iterations<<std::endl;
  90.     return 0;
  91. }
RAW Paste Data
Top