43 lines
682 B
Plaintext
43 lines
682 B
Plaintext
edit:add-var ++~ {|n| + $n 1 }
|
|
edit:add-var --~ {|n| + $n 1 }
|
|
|
|
edit:add-var sign~ {|n|
|
|
if (> $n 0) {
|
|
put 1
|
|
} elif (< $n 0) {
|
|
put -1
|
|
} else {
|
|
put 0
|
|
}
|
|
}
|
|
edit:add-var neg~ {|n| * $n -1 }
|
|
edit:add-var abs~ {|n|
|
|
if (< $n 0) {
|
|
neg $n
|
|
} else {
|
|
put $n
|
|
}
|
|
}
|
|
|
|
edit:add-var sum~ {|@numbers|
|
|
var s = 0
|
|
each {|e| set s = (+ $s e) } (to-list $numbers)
|
|
}
|
|
|
|
fn -minmax {|t @numbers|
|
|
var l = (to-list $@numbers)
|
|
if (== (count $l) 0) {
|
|
return
|
|
}
|
|
var m = $l[0]
|
|
each {|n|
|
|
if ($t $n $m) {
|
|
set m = $n
|
|
}
|
|
} $l[1..]
|
|
put $m
|
|
}
|
|
|
|
edit:add-var min~ {|@numbers| -minmax $'<~' $@numbers }
|
|
edit:add-var max~ {|@numbers| -minmax $'>~' $@numbers }
|