#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool hasSingleCycle(vector<int> array) {
//doesn't matter where you start in the cycle
//if there is a cycle, all elements will be in the valid cycle
vector<int> visitedIndex;
int currIndex = 0;
int indexVal = array.at(0);
visitedIndex.push_back(0);
while (visitedIndex.size() != array.size() + 1) {
currIndex = currIndex + indexVal;
if (currIndex < 0) {
cout << currIndex << " % " << array.size() << endl;
currIndex = currIndex % array.size();
cout << currIndex << endl;
currIndex = array.size() + currIndex;
cout << currIndex << endl;
}
else if (currIndex >= array.size()) {
currIndex = currIndex % array.size();
}
visitedIndex.push_back(currIndex);
indexVal = array.at(currIndex);
}
for (int i = 0; i < array.size(); i++) {
if (find(visitedIndex.begin(), visitedIndex.end(), i) == visitedIndex.end()) {
return false;
}
}
if (visitedIndex.at(array.size()) != 0) {
return false;
}
return true;
}
int main() {
// int z = -1%3;
// cout << z << endl;
vector<int> x = {-1, 2, 2};
bool y = hasSingleCycle(x);
return 0;
}