#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
std::vector<int> Arr {0,0,0,0};
std::size_t Step = 0;
std::size_t State = 0;
void prn();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool process1() {
Step++;
Arr[0]++;
int Summ = 0;
std::for_each(Arr.begin(), Arr.end(), [&](int &n){Summ += n;});
return Summ % 2 == 0;
}
bool process2() {
Step++;
Arr[1] += Arr[3] + 1;
int Summ = 0;
std::for_each(Arr.begin(), Arr.end(), [&](int &n){Summ += n;});
return Summ % 7 > 0;
}
bool process3() {
Step++;
Arr[2] += ((Arr[0]+Arr[1]) % 3 == 0) ? 0 : 7;
bool Flag = true;
std::for_each(Arr.begin(), Arr.end(), [&](int &n){if (n % 2 >0) Flag = false;});
return Flag;
}
bool process4() {
Step++;
Arr[3] += ((Arr[0]+Arr[2]) % 5 == 4) ? 0 : 1;
int Summ = 0;
std::for_each(Arr.begin(), Arr.end(), [&](int &n){Summ += n;});
return Summ > 24;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void load(int pass) {
if (pass == 1) {
State = 1;
prn();
} else {
State = 4;
Arr = {3,3,14,1};
Step = 9;
prn();
}
return;
}
void prn() {
std::cout << "Step: " << Step << "\t" << "Proc: " << State << "\t"
<< Arr[0] << "\t" << Arr[1] << "\t"
<< Arr[2] << "\t" << Arr[3] << "\n";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int main()
{
for (int i=1; i<3; i++) {
load(i);
bool cycle = true;
while (cycle) {
switch (State) {
case 1:
State = (process1()) ? 4:3; prn(); break;
case 2:
State = (process2()) ? 3:4; prn(); break;
case 3:
State = (process3()) ? 2:1; prn(); break;
case 4:
State = (process4()) ? 5:2; prn(); break;
default:
cycle = false; break;
}
}
std::cout << "----------------------------------------------------------------\n";
}
return 0;
}