Lua 手直し
最大値最小値は何のことはなかったので、軽くエラー処理を入れてみた。
わざわざget_minmax関数を置く必要はないが、Luaは複数の戻り値を返せるとのことだったので試しに。
function compare(x, y) if(x.weight < y.weight) then return 1 end end function get_minmax(t) return t[1].name, t[(# t)].name end function show_all(t) for i=1,(# t) do print(" --- "..t[i].name, t[i].weight) end end function main_loop() local list = {} while true do io.write(">> Input name : ") local name = io.read() repeat io.write(">> Input weight : ") local buf = io.read() weight = tonumber(buf) until type(weight) == "number" table.insert(list,{["name"]=name, ["weight"]=weight}) table.sort(list,compare) local min, max = get_minmax(list) print() show_all(list) print("\n".." [MIN : "..min.." / ".."MAX : "..max.."]".."\n") end end main_loop()