What about something like this?

       (|.~ ,.@i.@#)&.> n
    ┌─────┬─────────┬───┬───────┐
    │1 2 3│4 5 6 7 8│8 6│3 5 7 9│
    │2 3 1│5 6 7 8 4│6 8│5 7 9 3│
    │3 1 2│6 7 8 4 5│   │7 9 3 5│
    │     │7 8 4 5 6│   │9 3 5 7│
    │     │8 4 5 6 7│   │       │
    └─────┴─────────┴───┴───────┘

Skip Cave <[email protected]> wrote:
> Is there a more concise way to express m rotations of each of a set of
> items?
> 
> ]n=.1 2 3;4 5 6 7 8;8 6;3 5 7 9
> 
> ┌─────┬─────────┬───┬───────┐
> 
> │1 2 3│4 5 6 7 8│8 6│3 5 7 9│
> 
> └─────┴─────────┴───┴───────┘
> 
> m=. 0, 1, 2, 3, 4 NB. Number of rotations
> 
> ea =. each
> 
> 
> n,.(1|.ea n),.(2|.ea n),.(3|.ea n),.(4|.ea n)
> 
> ┌─────────┬─────────┬─────────┬─────────┬─────────┐
> 
> │1 2 3 │2 3 1 │3 1 2 │1 2 3 │2 3 1 │
> 
> ├─────────┼─────────┼─────────┼─────────┼─────────┤
> 
> │4 5 6 7 8│5 6 7 8 4│6 7 8 4 5│7 8 4 5 6│8 4 5 6 7│
> 
> ├─────────┼─────────┼─────────┼─────────┼─────────┤
> 
> │8 6 │6 8 │8 6 │6 8 │8 6 │
> 
> ├─────────┼─────────┼─────────┼─────────┼─────────┤
> 
> │3 5 7 9 │5 7 9 3 │7 9 3 5 │9 3 5 7 │3 5 7 9 │
> 
> └─────────┴─────────┴─────────┴─────────┴─────────┘
> 
> 
> Or better yet with no duplicated rotations::
> 
> 2 7$~.,n,.(1|.ea n),.(2|.ea n),.(3|.ea n),.(4|.ea n)
> 
> ┌─────────┬─────┬─────┬─────────┬─────────┬─────────┬─────────┐
> 
> │1 2 3 │2 3 1│3 1 2│4 5 6 7 8│5 6 7 8 4│6 7 8 4 5│7 8 4 5 6│
> 
> ├─────────┼─────┼─────┼─────────┼─────────┼─────────┼─────────┤
> 
> │8 4 5 6 7│8 6 │6 8 │3 5 7 9 │5 7 9 3 │7 9 3 5 │9 3 5 7 │
> 
> └─────────┴─────┴─────┴─────────┴─────────┴─────────┴─────────┘
> 
> Can this be done using iteration rather than explicitly listing each
> rotation?
> 
> Skip Cave
> Cave Consulting LLC
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to