Re: Simple Loop
- From: shapper <mdmoura@xxxxxxxxx>
- Date: Sat, 16 Jun 2007 14:05:14 -0700
On Jun 16, 9:32 pm, James Waldby <n...@xxxxx> wrote:
shapper wrote:
On Jun 15, 7:52 pm, "[Mr.] Lynn Kurtz" ...wrote:...
On Fri, 15 Jun 2007 11:24:05 -0700, shapper <... wrote:...
I have the following:
A = [1,2,3,4,5,6,7,8,9,10,11]
And I need to transform it to:
B = [1,4,7,10,2,5,8,11,3,6,9]
In your array A = [1,2,3,4,5,6,7,8,9,10,11], index them starting with
zero, so A[0] = 1, A[1] = 2, ..., A[10] = 11.
Now to calculate your new array B = [ B[0], B[1],...B[10] ]
you can just use B[k] = A[3k mod 11] for k = 0 to 10.
...So, for example, B[5], which is the 6th term in the new array,is:
B[5] = A[15 mod 11] = A[4] = 5.
I tried the way your described using the following VB.NET code with an[snip code]
18 elements array:
I get the following sequence:
18
1
4
7
10
13
16
1
4
7
10
[snip other numbers]
This is very strange because the numbers are repeating. Any idea of what
I am doing wrong?
a*k mod m (eg, 3k mod 11) will give m distinct values (as k goes from 0 to m-1)
if and only if a and m are coprime (ie, have no integer divisors in common).
It isn't obvious to me what sequence you want when a=3 and m=18.
--
-jiw
Hi James,
Let me give you an example what I am trying to do:
I have an array of strings. Consider the following example:
cities = {Berlin, Lisbon, London, Madrid, New York, Paris, Roma,
Tokio}
The loop that displays the cities do it the following way:
Cities in 3 columns:
Berlin Lisbon London
Madrid New York Paris
Roma Tokio
1 -----> 2 -----> 3
4 -----> 5 -----> 6
7 -----> 8
Cities in 2 columns:
Berlin Lisbon
London Madrid
New York Paris
Roma Tokio
1 -----> 2
3 -----> 4
5 -----> 6
7 -----> 8
But I want to fill the columns as follows:
Cities in 3 columns:
Berlin Madrid Roma
Lisbon New York Tokio
London Paris
1 -----> 4 -----> 7
2 -----> 5 -----> 8
3 -----> 6
Cities in 2 columns:
Berlin New York
Lisbon Paris
London Roma
Madrid Tokio
1 -----> 5
2 -----> 6
3 -----> 7
4 -----> 8
The loop that displays the cities does it always in the direction
showed.
So I need to rearrange the array of strings so that my Display Loop
shows the cities as I described.
I want to display all cities in the string array.
Well, I hope I explained the situation well.
Thank You,
Miguel
.
- Follow-Ups:
- Re: Simple Loop
- From: James Waldby
- Re: Simple Loop
- References:
- Simple Loop
- From: shapper
- Re: Simple Loop
- From: [Mr.] Lynn Kurtz
- Re: Simple Loop
- From: shapper
- Re: Simple Loop
- From: James Waldby
- Simple Loop
- Prev by Date: Re: Integers -> Strings
- Next by Date: Re: Question about a^2+b^2=4k+1 prime ...
- Previous by thread: Re: Simple Loop
- Next by thread: Re: Simple Loop
- Index(es):
Relevant Pages
|