def cycle(a, i=0)
puts a.join
cycle(a + [a.shift], i+1) if i < 20
end
cycle '10000'.split(//).map &:to_s
10000
00001
00010
00100
01000
10000
00001
00010
00100
01000
10000
00001
00010
00100
01000
10000
00001
00010
00100
01000
10000
# or
c2 =->(x,i=0){p x.join; d.call x+[x.shift],i+1 if i<20}
c2.call '10000'.split(//).map &:to_s
# or
def c3(a,i=0); p a.join; c3(a+[a.shift],i+1) if i<20 end
c3 '10000'.split(//).map &:to_s
# or without recursion
out = 10.times.map {a = a[1..-1] + [a[0]]}
# or
out = 10.times.map {a[1..-1].concat [a[0]]}
# or
out = (0..10).map {a[1..-1].concat [a[0]]}
Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/zRwwM0Lal2g/11093