### Sequence comparing

I am writing a program that takes an array A and shuffles it and saves the shuffled elements into array B. This I have finished. Now I am writing a function that takes array B and according to the same rules that shuffled array A, shuffles B so that its elements are the same as A.
 ``123456789101112131415161718192021222324`` ``````int A[8] = {0,1,2,3,4,5,6,7} int B[8] = {7,5,3,1,0,2,4,6} int same = 0; int diff = 0; int count = 0; for(int i=0; i

This should display 4, because it would take 4 shuffles to restore array B to be the same as array A. I do not see where I went wrong.
line 7
`for(int i=0; i<value; i++)`

line 15
` int i = 0;`

Did you mean to reset i every time it goes through the if loop on line 14?
And if so, why did you declare it twice? seems a bit pointless.
Last edited on
So I changed it to
 ``1234567891011121314151617181920212223242526`` `````` int A[8] = {0,1,2,3,4,5,6,7} int B[8] = {7,5,3,1,0,2,4,6} int same = 0; int diff = 0; int count = 0; for(int i=0; i

}
But still get the same answer. What this loop should do it take the array B, as long as it is not the same as A, and loop according to those rules, until the elements of B are the same as element A, and count how many times it had to loop.

So lets say array A is 0 1 2 3 4 5 6 7
and B is 7 5 3 1 0 2 4 6
if B loops 1 more time 6 2 1 5 7 3 0 4
1 more time 4 3 5 2 6 1 7 0
and one last time 0 1 2 3 4 5 6 7
as you see after four times it went back to the original.
can you link the entire program?
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990`` ``````//Monge's Shuffle #include #include #include using namespace std; const int SIZE = 1000; //determines where to put a number according to whether it is odd or even, starting backwards from the highest number to the lowest. //PRE: takes two arrays, A filled with numbers 1 to n-1, and shuffles it according to monge's shuffle rules //POST: Monge's shuffle is saved into array B void shuffle (int source[], int destination [], int count) { int i = 0; while (i> value; if (value >= 2 && value <= 1000) { for (int i = 0; i= 2 && value <= 1000) { for (int i = 0; i
Last edited on
This is the small version with preset arrays.
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445`` ``````#include #include #include #include using namespace std; const int SIZE = 8; void display (int A[],int count) { for (int i = 0; i
It should basically tell me how many times I would have to loop array B to get back to A. Or I guess How many times to loop array A so that it gets back to original.
looping array A 4 times would return it to its original state.
original 0 1 2 3 4 5 6 7
1st loop 7 5 3 1 0 2 4 6
2nd loop 6 2 1 5 7 3 0 4
3rd loop 4 3 5 2 6 1 7 0
4th loop 0 1 2 3 4 5 6 7
Topic archived. No new replies allowed.