#! perl -sw use strict; sub roundRobin { my @q; my $next = -1; my %self = ( values => sub { return @q[@_]; }, size => sub { return scalar @q; }, pos => sub { return 0+$next; }, add => sub { return push @q, @_; }, del => sub { my ($i, %del) = (0); @del{@_} = undef; @q = grep { exists $del{$_} ? ($next -= $i <= $next) && 0 : ++$i } @q; return 1; }, next => sub { return undef if not @q; ++$next; $next %= @q; return $q[$next]; }, shuffle => sub { my $t; $t = $_ + rand @q - $_ and @q[$_, $t] = @q[$t, $_] for (0..$#q); }, ); return %self; } my %rr = roundRobin(); $rr{add}( 'a' .. 'z' ); print $rr{size}(), $rr{values}(0..$rr{size}()-1), $/; $rr{add}( 'k' .. 'q' ); print $rr{size}(), $rr{values}(0..$rr{size}()-1), $/; $rr{shuffle}(); while ( my $item = $rr{next}() ) { my $pos = $rr{pos}(); print " @{[$rr{values}( 0 .. $pos -1 )]}". "<@{[$rr{values}($pos)]}>". "@{[$rr{values}($pos+1..$rr{size}()-1 )]}"; if (rand(8) < 1) { my $new = chr(95+rand 26); $rr{add}( $new ); print "\t --added ", $new; } if (rand(8) < 1) { my $toDelete = $item; $toDelete = do { $rr{values}( rand( $rr{size}()) ) } until $toDelete ne $item; print "\t--deleting: '", $toDelete; $rr{del}( $toDelete ); } print $/; select undef, undef, undef, .5; } #### C:\test>^Croundrobin 26abcdefghijklmnopqrstuvwxyz 33abcdefghijklmnopqrstuvwxyzklmnopq p z e u h j s a k w l o r k g v m x t q d i c m n p b l f y o n q

z e u h j s a k w l o r k g v m x t q d i c m n p b l f y o n --added j q pe u h j s a k w l o r k g v m x t q d i c m n p b l f y o n j q p zu h j s a k w l o r k g v m x t q d i c m n p b l f y o n j q p z eh j s a k w l o r k g v m x t q d i c m n p b l f y o n j --deleting: 'v q p z e uj s a k w l o r k g m x t q d i c m n p b l f y o n j --added _ --deleting: 'e q p z u hs a k w l o r k g m x t q d i c m n p b l f y o n j _ --deleting: 'i q p z u h ja k w l o r k g m x t q d c m n p b l f y o n j _ q p z u h j sk w l o r k g m x t q d c m n p b l f y o n j _ q p z u h j s aw l o r k g m x t q d c m n p b l f y o n j _ q p z u h j s a kl o r k g m x t q d c m n p b l f y o n j _ q p z u h j s a k wo r k g m x t q d c m n p b l f y o n j _ q p z u h j s a k w lr k g m x t q d c m n p b l f y o n j _ --added v q p z u h j s a k w l ok g m x t q d c m n p b l f y o n j _ v q p z u h j s a k w l o rg m x t q d c m n p b l f y o n j _ v q p z u h j s a k w l o r km x t q d c m n p b l f y o n j _ v --added b q p z u h j s a k w l o r k gx t q d c m n p b l f y o n j _ v b q p z u h j s a k w l o r k g mt q d c m n p b l f y o n j _ v b q p z u h j s a k w l o r k g m xq d c m n p b l f y o n j _ v b q p z u h j s a k w l o r k g m x td c m n p b l f y o n j _ v b --deleting: 's q p z u h j a k w l o r k g m x t qc m n p b l f y o n j _ v b --deleting: 'z q p u h j a k w l o r k g m x t q dm n p b l f y o n j _ v b q p u h j a k w l o r k g m x t q d cn p b l f y o n j _ v b q p u h j a k w l o r k g m x t q d c mp b l f y o n j _ v b q p u h j a k w l o r k g m x t q d c m n

b l f y o n j _ v b q p u h j a k w l o r k g m x t q d c m n pl f y o n j _ v b q p u h j a k w l o r k g m x t q d c m n p bf y o n j _ v b q p u h j a k w l o r k g m x t q d c m n p b ly o n j _ v b --added b q p u h j a k w l o r k g m x t q d c m n p b l fo n j _ v b b q p u h j a k w l o r k g m x t q d c m n p b l f yn j _ v b b --added l q p u h j a k w l o r k g m x t q d c m n p b l f y oj _ v b b l q p u h j a k w l o r k g m x t q d c m n p b l f y o n_ v b b l --added g q p u h j a k w l o r k g m x t q d c m n p b l f y o n j<_>v b b l g q p u h j a k w l o r k g m x t q d c m n p b l f y o n j _b b l g q p u h j a k w l o r k g m x t q d c m n p b l f y o n j _ vb l g q p u h j a k w l o r k g m x t q d c m n p b l f y o n j _ v bl g q p u h j a k w l o r k g m x t q d c m n p b l f y o n j _ v b bg --deleting: '_ q p u h j a k w l o r k g m x t q d c m n p b l f y o n j v b b l p u h j a k w l o r k g m x t q d c m n p b l f y o n j v b b l g q

u h j a k w l o r k g m x t q d c m n p b l f y o n j v b b l g q ph j a k w l o r k g m x t q d c m n p b l f y o n j v b b l g q p uj a k w l o r k g m x t q d c m n p b l f y o n j v b b l g q p u ha k w l o r k g m x t q d c m n p b l f y o n j v b b l g --deleting: 'h q p u jk w l o r k g m x t q d c m n p b l f y o n j v b b l g q p u j aw l o r k g m x t q d c m n p b l f y o n j v b b l g q p u j a kl o r k g m x t q d c m n p b l f y o n j v b b l g q p u j a k wo r k g m x t q d c m n p b l f y o n j v b b l g q p u j a k w lr k g m x t q d c m n p b l f y o n j v b b l g