Hi All,
I have created some simple code below that shuffles an array (called original) based on an order that's specified in another array (shuffleOrder) and stores the results in a 3rd array called shuffled.
What i'd like to do now is, given i know the original "shuffleOrder" - is now how to un-shuffle it and store the contents in the unshuffled array.
I cant think how to do this.....could anyone lend a hand?
thanks
Caroline.
int arraySize = 5;
int original[] = {1, 2, 3, 4, 5};
int shuffledOrder[] = {0, 4, 1, 3, 2};
int shuffled[5];
int unshuffled[5];
void setup(){
Serial.begin(115200);
Serial.println("Original:");
for (int i = 0 ; i < arraySize ; i++) {
Serial.println(original[i]);
}
Serial.println("Shuffled:");
for (int i = 0 ; i < arraySize ; i++) {
shuffled[i] = original[shuffledOrder[i]];
Serial.println(shuffled[i]);
}
}
void loop(){
}