[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: arbitrary rotating values of an array
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: arbitrary rotating values of an array |
Date: |
Mon, 9 Jan 2012 23:35:28 -0500 |
On 9 January 2012 22:51, Rick T <address@hidden> wrote:
>
> Greetings All
>
> I'm trying to arbitrarily rotate the values of an array but the rot commands
> don't seem to work for me.
>
> Example
> array=[1,2,3,4,5]
> I would like the array to be placed in a for loop so it steps through each
> iteration
> iteration1 of array=[2,3,4,5,1]
> iteration2 of array=[3,4,5,1,2]
> iteration3 of array=[4,5,1,2,3]
> iteration4 of array=[5,1,2,3,4]
This sounds like an X-Y problem:
http://www.perlmonks.org/index.pl?node_id=542341
Regardless, it's simple to do:
cycle_permute = @(array, k) [array(k+1, end), array(1:k)]
cycle_permute(array, 1)
cycle_permute(array, 2)
etc
- Jordi G. H.