gen=require("gen") printf=gen.printf floor=math.floor sqrt=math.sqrt abs=math.abs local function dbg(...) if DBG then print(...) end end -- original tpr() is in "gen.lua" -- improved local function tpr(...) t = {...} if type(t[1])=="string" then print(t[1]) remove(t,1) end local i a = t[1] for i=#a,0,-1 do print(i,a[i]) end for k,v in pairs(a) do if type(k)~="number" then print(k,v) end end end local function dup(t) -- create new table from t local tn tn = {} for k,v in pairs(t) do if type(v)=="table" then tn[k] = dup(v) else tn[k] = v end end return tn end local function gcd(a,b) -- a,b: int --print("gcd") local c a = abs(a) b = abs(b) assert(a+b>0) while b > 0 do c = a % b a,b = b,c --print("a,b,c",a,b,c) end return a end --[[ print("gcd") print(gcd(12,15)) --> 3 print(gcd(0,15)) --> 15 print(gcd(0,0)) -->fail os.exit() --]] return { dbg=dbg, tpr=tpr, dup=dup, gcd=gcd, }