-- Z -- http://blog.so-net.ne.jp/rainyday/2007-07-16 function table.copy(t) local t2 = {} for k,v in pairs(t) do t2[k] = v end return t2 end function enum(items, enums, n) if n == 0 then coroutine.yield(enums) else for i,v in ipairs(items) do local lenums = table.copy(enums) table.insert(lenums, v) enum(items, lenums, n-1) end end end function make_expr(ops) local expr = "" for i,v in ipairs(ops) do expr = expr .. i .. v end return expr .. (table.getn(ops)+1) end function gen_expr(ops, n) local co = coroutine.create(function() enum(ops, {}, n) end) return function() local code, res = coroutine.resume(co) return res and make_expr(res) end end i=0 for e in gen_expr({"+", "-", "*", "/", ""}, 8) do local result = loadstring("return "..e)() if result == 100 then print(e.."="..result) i = i + 1 end end print(i.." patterns found")