Re: Simple Loop



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
18 elements array:
[snip code]
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

.



Relevant Pages

  • Re: Heathrow = Thrust Reversers deployed
    ... I think you'd find that many residents of cities such as New York and ... Paris do not have driver's licenses, and that hardly makes them dense. ...
    (rec.aviation.piloting)
  • Re: been running a day camp all week...
    ... say, London, where I grew up? ... New York is worse for traffic, ... the roads and it's not a lot better round here at times. ... big cities are big cities and a different matter entirely. ...
    (uk.people.support.depression)
  • Re: Violent Crime Up for 1st Time in 5 Years
    ... Despite the national numbers, Detroit, Los Angeles and New York were ... among several large cities that saw the number of murders drop. ... violent crime rates (with murder serving as a proxy for violent crime ... Las Vegas, ...
    (alt.true-crime)
  • Re: The worlds best cities for quality of life
    ... New York, conducts a survey of the world's leading cities to determine ... better quality of life than their counterparts in the US. ...
    (rec.gambling.poker)
  • Re: The worlds best cities for quality of life
    ... New York, conducts a survey of the world's leading cities to determine ... better quality of life than their counterparts in the US. ...
    (rec.gambling.poker)