Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Counter array problem

Posted on 2004-11-30
10
Medium Priority
?
194 Views
Last Modified: 2010-04-17
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
0
Comment
Question by:Naveen Swamy
  • 5
  • 2
8 Comments
 
LVL 9

Author Comment

by:Naveen Swamy
ID: 12713376
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.

Thanks in advance,
0
 
LVL 1

Expert Comment

by:Justin_Huang
ID: 12713473
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
 
LVL 9

Author Comment

by:Naveen Swamy
ID: 12713532
thanks for posting
i need to achive this in vbscript or vb
Plz help
Thanks
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
Justin_Huang earned 252 total points
ID: 12713589
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
 
LVL 9

Author Comment

by:Naveen Swamy
ID: 12714158
how to randomize the combinations in each row???????
plz help
Regards,
0
 
LVL 9

Author Comment

by:Naveen Swamy
ID: 12714160
how to randomize the combinations in each row in each round???????
plz help
Regards,
0
 
LVL 9

Author Comment

by:Naveen Swamy
ID: 12714191
     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
 

Assisted Solution

by:RajamNaidu
RajamNaidu earned 248 total points
ID: 12714449
'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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Progress

804 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question