ID:1169398
 
Keywords: procs
These are just some of the procedures that I've had for a while now, having no practical use for them. Nonetheless, I thought I'd share it anyway; one of you might find a use for one of them, hopefully.

    //  Sorts @param a, b, c ascendingly, returning the smallest number first and the highest number last.
sort(a, b, c)
if(!isnum(b) || !isnum(a) || !isnum(c)) return 0
var min = min(a, min(b, c))
var max = max(a, max(b, c))
. = (a + b + c - min - max)
usr << "[min], [.], [max]"

// Gets the GCD(Greatest Common Divisor) of p & q, using a recursive method.
gcd(p, q)
. = (q == 0) ? p : gcd(q, p % q)


/* Using some simple boolean logic, you can easily check if @param y is a leap year without
a bunch of if statements.
@return 1(TRUE) if @param y is a leap year, 0(FALSE) otherwise.
*/

is_leap(y)
. = y % 4 == 0
. = . && (y % 100 != 0)
. = . || (y % 400 == 0)
return .
In the sort() procedure, you might need to change the last . to var med, since it might actually return the median before the actual sorted numbers.

EDIT: For people who prefer the non-recursive, faster method:
proc/fast_gcd(p, q)
while(q != 0)
. = q
q %= p
p = .
return p