in reply to Calculate easiest way to 'level results'
Update: I interrupt my own post to point out that there is no reason to do a shuffle if you don't have enough total points. Just figure out how long you need to wait, wait that long, and then shuffle.
So shuffle your points to be 25/36 of an hour from having what you need:
HP: 50-(25/36)*12
Mana: 107-(25/36)*17
Spells: 38-(25/36)*7
should do it, not counting some rounding errors.
Update: here's some ham-handed code (updated again to optimize leftover placement):
# Have/gain per hour my @points = ([60,12,'HP'],[80,17,'Mana'],[31,7,'Spells']); my @need = (51, 107, 38); use List::Util qw(sum reduce); my $total_have = sum map $_->[0], @points; my $total_need = sum @need; print "You have $total_have and need $total_need\n"; my $diff_need = $total_need - $total_have; my $gain_per_hour = sum map$_->[1], @points; print "You need $diff_need more, and you gain them at $gain_per_hour p +er hour\n"; my $time_left = $diff_need/$gain_per_hour; print "That should take $diff_need/$gain_per_hour hour(s).\n"; my @new_values = map $need[$_] - $time_left * $points[$_][1], 0..$#nee +d; my $leftover = $total_have - sum map int, @new_values; # Put leftovers on furthest-from-goal while ($leftover--) { my $slow = reduce { $new_values[$a]-int($new_values[$a]) > $new_values[$b]-int($new_va +lues[$b]) ? $a : $b } 0..$#points; $new_values[$slow]++; } @new_values = map int, @new_values; for (0..$#need) { print "New value for $points[$_][2]: $new_values[$_]\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Calculate easiest way to 'level results'
by ikegami (Patriarch) on Sep 19, 2007 at 17:26 UTC | |
by Roy Johnson (Monsignor) on Sep 19, 2007 at 17:51 UTC |