2021-12-11 21:09:02 +00:00
|
|
|
edit:add-var ++~ {|n| + $n 1 }
|
|
|
|
edit:add-var --~ {|n| + $n 1 }
|
2021-08-24 18:45:25 +00:00
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
edit:add-var sign~ {|n|
|
2021-08-24 18:45:25 +00:00
|
|
|
if (> $n 0) {
|
|
|
|
put 1
|
|
|
|
} elif (< $n 0) {
|
|
|
|
put -1
|
|
|
|
} else {
|
|
|
|
put 0
|
|
|
|
}
|
|
|
|
}
|
2021-12-11 21:09:02 +00:00
|
|
|
edit:add-var neg~ {|n| * $n -1 }
|
|
|
|
edit:add-var abs~ {|n|
|
2021-08-24 18:45:25 +00:00
|
|
|
if (< $n 0) {
|
|
|
|
neg $n
|
|
|
|
} else {
|
|
|
|
put $n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
edit:add-var sum~ {|@numbers|
|
2021-08-27 20:06:49 +00:00
|
|
|
var s = 0
|
2021-12-11 21:09:02 +00:00
|
|
|
each {|e| set s = (+ $s e) } (to-list $numbers)
|
2021-08-24 18:45:25 +00:00
|
|
|
}
|
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
fn -minmax {|t @numbers|
|
2021-08-27 20:06:49 +00:00
|
|
|
var l = (to-list $@numbers)
|
2021-08-24 18:45:25 +00:00
|
|
|
if (== (count $l) 0) {
|
|
|
|
return
|
|
|
|
}
|
2021-08-27 20:06:49 +00:00
|
|
|
var m = $l[0]
|
2021-12-11 21:09:02 +00:00
|
|
|
each {|n|
|
2021-08-24 18:45:25 +00:00
|
|
|
if ($t $n $m) {
|
2021-10-13 18:49:48 +00:00
|
|
|
set m = $n
|
2021-08-24 18:45:25 +00:00
|
|
|
}
|
|
|
|
} $l[1..]
|
|
|
|
put $m
|
|
|
|
}
|
|
|
|
|
2021-12-11 21:09:02 +00:00
|
|
|
edit:add-var min~ {|@numbers| -minmax $'<~' $@numbers }
|
|
|
|
edit:add-var max~ {|@numbers| -minmax $'>~' $@numbers }
|