Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Round robin processing

by rsFalse (Hermit)
on Sep 10, 2019 at 10:21 UTC ( #11105942=note: print w/replies, xml ) Need Help??


in reply to Round robin processing

Tried this for fun. But it becomes slower as bucket count increases:
#!/usr/bin/perl -l # https://www.perlmonks.org/?node_id=11105885 use strict; use warnings; use Data::Dumper; my @a = 1 .. 14; my $buckets = 4; my @buckets; my $place = ','; $_ = $place x ( @a + $buckets - 1 ); my $space = $buckets - 1; my @bucket; / (?(?{ $buckets <= pos }) (*ACCEPT) ) (?{ @bucket = (); }) (?: .{$space} $place (?{ push @bucket, ( pos ) - $buckets }) )++ (?{ push @buckets, [ @a[ @bucket ] ] }) (*FAIL) /x; print Dumper( @buckets );
OUTPUT:
$VAR1 = [ 1, 5, 9, 13 ]; $VAR2 = [ 2, 6, 10, 14 ]; $VAR3 = [ 3, 7, 11 ]; $VAR4 = [ 4, 8, 12 ];

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2020-01-23 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?