ID:179644
 
Lets say I had 4 numbers, and I wanted to remove the lowest value and add up the other three. How would I go about doing this?

Thanks in advance.
Evilkevkev wrote:
Lets say I had 4 numbers, and I wanted to remove the lowest value and add up the other three. How would I go about doing this?

Thanks in advance.

like D&D????
In response to Air _King
Yes, like D&D.
In response to Evilkevkev
In response to Cinnom
Thanks!
[EDIT]
Is this the best way to do it? Or is there a more efficient way?
var/r1 = rand(1,6)
var/r2 = rand(1,6)
var/r3 = rand(1,6)
var/r4 = rand(1,6)
var/stat1 = (r1+r2+r3+r4)-min(r1,r2,r3,r4)
In response to Evilkevkev
There may be a more efficient way, but that looks fine to me.
In response to Evilkevkev
I think your code will work just fine. However, keep in mind that it's only going to work for removing one item from the list. If you want to take five values and remove the smallest two, then you need to find a more complex solution.

Probably the best all-around solution for more complicated problems of this sort is to write a proc to sort a list of numbers in either ascending or descending order, then use Cut() to chop off part of the list, and have another proc take care of adding everything up. My current project is going to have to sort the results of dice rolls, too, so I may as well toss you this freebie code, in case you need it:
proc/SortDice(list/dice)
var/i
var/j
var/k
for(i=1,i<dice.len,++i)
k=i
for(j=i+1,j<=dice.len,++j) if(dice[j]>dice[k]) k=j
if(k!=i)
j=dice[i]
dice[i]=dice[k]
dice[k]=j

The proc doesn't return anything, because it's sorting the list that's sent to it. This sorts in descending order (highest dice come first in the list); for ascending order, change dice[j]>dice[k] to dice[j]<dice[k]. And of course this will sort anything you can compare with > and <, even strings. Odds are somebody wrote this into a library somewhere, but I like to write my own sort routines anyway.

Lummox JR