Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Round robin processing

by rsFalse (Chaplain)
on Sep 10, 2019 at 10:21 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11105942]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-25 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found