- Calculator の場合:
構文: median(リスト)
実行結果:
- Nspired Lua で実行する場合:
seq2 = {9,9,1,5,4,7,0,3,9,2} function median(list) local temp = "{"..table.concat(list, ",").."}" --return math.eval("median("..temp..")") return math.eval(string.format("median(%s)", temp)) end function on.resize() print(median(seq2)) end
実行結果:
- Lua だけで組む場合:
seq2 = {9,9,1,5,4,7,0,3,9,2} function median(list) local num = #list local pos = math.ceil(num / 2) table.sort(list) return num % 2 == 0 and (list[pos] + list[pos+1]) / 2 or list[pos] end print(median(seq2))
実行結果:
――――――――――――――――――――――――――――――
Wolfram の場合:
構文: Median[リスト]
実行結果:
――――――――――――――――――――――――――――――
Excel の場合:
構文: MEDIAN(始点セル:終点セル)
実行結果: