Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Ruby

Idiom #194 Circular shift of a two-dimensional array

Given an array a, set b to an array which has the values of a along its second dimension shifted by n. Elements shifted out should come back at the other end.

b  = a.map{|ar| ar.rotate(n) }

Negative n is fine
b = cshift(a,n,dim=2)

New implementation...
< >
tkoenig