I don't understand why you make a case distinction for users with and without weight. Just assume that that users without one have weight 1.
Also I don't understand if there are any constraints related to how work can be redistributed. If not, simply add all the weights (and 1 for unweighted users), divide the total work units by that sum, and then you have the amount of work a "normal" user has to. Scale it by each users's weight to get the work she has to do.
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use List::Util qw/sum/;
my %user_weight = (DREW => .5, TIM => 2,);
my $total_work;
while (<DATA>) {
my @cols = split;
$user_weight{$cols[0]} //= 1;
$total_work += $cols[1];
}
my $total_weights = sum values %user_weight;
my $work_per_unit = $total_work / $total_weights;
for my $u (sort keys %user_weight) {
printf "%s: %.2f\n", $u, $work_per_unit * $user_weight{$u};
}
__DATA__
TIM 150
JOE 124
JACK 111
KATE 145
DREW 177
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|