Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Round robin processing

by dbuckhal (Hermit)
on Sep 10, 2019 at 02:33 UTC ( #11105921=note: print w/replies, xml ) Need Help??


in reply to Round robin processing

very nice solutions, All!

Me? late to the party as usual, but my contribution:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @array = qw(1 2 3 4 5 6 7 8 9 10 11 12); my $size = @array; my $count = int($size / 4); my $counter = 1; my $result = {}; for (0..2) { push @{$result->{$counter++}}, @array[0 ..$count-1]; @array = @array[$count .. $#array]; } push @{$result->{$counter}}, @array[0 ..$#array] if @array; print Dumper($result); __output__ $VAR1 = { '1' => [ '1', '2', '3' ], '3' => [ '7', '8', '9' ], '4' => [ '10', '11', '12' ], '2' => [ '4', '5', '6' ] };

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11105921]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2019-10-18 18:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?