# Counter array problem

hi,
its a strange question but how to approach
i have got a counter
iCtr = 8
and the no. is displayed like this for the first round

1  8
2  7
3  6
4  5
the 8 no.s are arranged in the above order for first round.

2nd round
1  7
8  6
2  5
3  4

3rd round
1  6
7  5
8  4
2  3

4th round
1  5
6  4
7  3
8  2

5th round
1  4
5  3
6  2
7  8

6th round
1  3
4  2
5  8
6  7

7th round
1  2
3  8
4  7
5  6

8th round
1  8
2  7
3  6
4  5

now how to do this programmaticaly? and this counter can also vary from 8 to 10 or 6 or 12 or anything. how to achieve this?
plz do answer as this is lil urgent.
Regards,
M.Naveen Swamy
LVL 9
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Yash Infinite Solutions Private LimitedAuthor Commented:
iCtr = 8
and currently it has 4 columns ( iCtr/2), if iCtr =10 then it would have 5 columns (iCtr/2)
and iCtr would always be even no.

0
Commented:
Hi,
Here is the C code for you.
Justin
----------------------------------------------------

#include <stdio.h>

#define iCtr      8

void main(void)
{

int   counters[iCtr], temp;
int   i, round;
for (i=0;i<iCtr;i++)
counters[i] = i+1;
for (round=1;round<=iCtr;round++) {
printf("\nround: %d",round);
for (i=0;i<iCtr/2;i++)
printf("\n%d   %d",counters[i], counters[iCtr-i-1]);
temp = counters[iCtr-1];
for (i=1;i<iCtr-1;i++)
counters[iCtr-i] = counters[iCtr-i-1];
counters[1] = temp;
}
}
0
Yash Infinite Solutions Private LimitedAuthor Commented:
thanks for posting
i need to achive this in vbscript or vb
Plz help
Thanks
0
Commented:
Sorry but I am not familar with vb/vb script.
Just let you know how I do.

initial (1st round)
[1][2][3][4] [5][6][7][8]

for each round, repeat (1) ~ (3):
(1) Save the last element.
temp = counters[iCtr-1];

now, temp=8.

(2) Shift the array to right except the first element.

[1][2][2][3] [4][5][6][7]

(3) Put temp to the second element.
counters[1] = temp;

[1][8][2][3] [4][5][6][7]
This is the result of 2nd round
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Yash Infinite Solutions Private LimitedAuthor Commented:
how to randomize the combinations in each row???????
plz help
Regards,
0
Yash Infinite Solutions Private LimitedAuthor Commented:
how to randomize the combinations in each row in each round???????
plz help
Regards,
0
Yash Infinite Solutions Private LimitedAuthor Commented:
Round:1)

2 7
1 8
3 6
4 5
Round:2)
3 4
2 5
8 6
1 7
Round:3)
7 5
1 6
8 4
2 3
Round:4)
6 4
8 2
1 5
7 3
Round:5)
5 3
6 2
1 4
7 8
Round:6)
1 3
5 8
4 2
6 7
Round:7)
3 8
5 6
1 2
4 7
Round:8)
1 8
2 7
3 6
4 5
0
Commented:
'Place this code at appropriate place this is useful for the first round
' Maxcounter can be changed to 10,12 or what ever depending on the need

Dim i, limit As Integer
maxCounter = 8
limit = (maxCounter / 2) - 1
TextBox1.Text = " "
For i = 0 To limit
arrayNumbers(i) = i + 1
TextBox1.Text = TextBox1.Text & " " & arrayNumbers(i)

Next

For i = maxCounter - 1 To limit + 1 Step -1
arrayNumbers(i) = i + 1
TextBox1.Text = TextBox1.Text & " " & arrayNumbers(i)
Next
' Place this code at appropriate place, this will be calling the iterations for subsequent rounds

Dim i, j As Integer
For i = 1 To maxCounter - 1
moveArray(arrayNumbers, maxCounter)
Next

Private Sub moveArray(ByRef array() As Integer, ByVal maxElement As Integer)
' This function moves all the array elements from 2nd position to the last but one
' to the next position and the last element is placed as the second element
Dim lastNumber, i As Integer
lastNumber = array(maxElement - 1)
For i = maxElement - 2 To 1 Step -1
array(i + 1) = array(i)
Next
arrayNumbers(1) = lastNumber
End Sub
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.