Take your comment, and put it into data. Derive everything from it. I just happen to like AoH's, as it's easy to extend it out more.
#/usr/bin/perl use strict; use warnings; use Readonly; my @volunteers = ( { name => "Ben", chunks => 5 }, { name => "Scott", chunks => 4 }, { name => "Jim", chunks => 1 }, ); my $current = 2192; Readonly my $CHUNKSIZE => 200; use List::Util qw(sum); my $total_volunteer_chunks = sum map { $_->{chunks} } @volunteers; sub volunteer_for { my $n = shift() % $total_volunteer_chunks; for my $v (@volunteers) { $n -= $v->{chunks}; if ($n < 0) { return $v; } } } for my $chunk (0..98) { my $end = $current + $CHUNKSIZE; my $victim = volunteer_for($chunk)->{name}; print "$current-$end\t\t$victim\n"; $current = $end + 1; }
Update: Fixed the code. It works now.
In reply to Re: Fair schedule allocation?
by Tanktalus
in thread Fair schedule allocation?
by oko1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |