in reply to Calculate easiest way to 'level results'

Kind of an interesting math problem. Since the points are all apparently interchangeable, you can start by adding everything up: You have 60+80+31=171 points, and you need 51+107+38=196. That leaves you 25 points short. You gain 12+17+7=36 per hour. So you'll need something under an hour to gain your points. 25/36 of an hour, to be exact.

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"; }

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Calculate easiest way to 'level results'
by ikegami (Patriarch) on Sep 19, 2007 at 17:26 UTC

    If the character is far from his goal, you might subtract more than you are allowed.

    my @points = ([10,12,'HP'],[10,17,'Mana'],[10,7,'Spells']); my @need = (40, 40, 40);
    You have 30 and need 120 You need 90 more, and you gain them at 36 per hour That should take 90/36 hour(s). New value for HP: 10 New value for Mana: -2 <----------- New value for Spells: 22
      In that case, it is better to wait to do any shuffling. The total time required to achieve your goal will be longer if you choose a sub-optimal distribution of points. As I noted in my now-often-updated original post, there's no reason you shouldn't just wait until you have the required number of points, anyway.

      Caution: Contents may have been coded under pressure.