This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function print_lua_table (lua_table, indent) | |
indent = indent or 0 | |
for k, v in pairs(lua_table) do | |
if type(k) == "string" then | |
k = string.format("%q", k) | |
end | |
local szSuffix = "" | |
if type(v) == "table" then | |
szSuffix = "{" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function split(str, splitor, nMatchModel) | |
splitor = splitor or ',' | |
nMatchModel = nMatchModel or true | |
local strArray = {} | |
local nStart = 1 | |
local splitorLen = string.len(splitor) | |
local index = string.find(str, splitor, nStart, nMatchModel) | |
while index do | |
strArray[#strArray + 1] = string.sub(str, nStart, index - 1) | |
nStart = index + splitorLen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
我有一个小书包呀咿呀咿呀呦,贪心算法求次优解 | |
由调用者保证nNum的合法性(nNum >= 0 and nNum <= #tbNumSet) | |
]] | |
function FindCloseSet(nTarget, nNum, tbNumSet) | |
local tbResult = {} | |
local nSum = 0 | |
local nLocal = 1 | |
for i = 1, nNum do | |
nSumnSum = nSum + tbNumSet[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
计算斜率:0和无穷大的情况简化处理了 | |
]] | |
function get_slope(nPosX1, nPosY1, nPosX2, nPosY2, nPosX3, nPosY3) | |
local nSlope1, nSlope2, nSlope3 | |
if nPosX1 == nPosX2 then | |
nSlope1 = 99999999 --设置一个近似无穷斜率 | |
else | |
nSlope1 = (nPosY1 - nPosY2) / (nPosX1 - nPosX2) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Fisher_Yates_Shuff随机算法 | |
local function shuffarray_fisher_yates(num) | |
local rand_seq = {} | |
for i = num, 1, -1 do | |
local idx = math.random(i) | |
local temp = rand_seq[i] or i | |
rand_seq[i] = (rand_seq[idx] or idx) | |
rand_seq[idx] = temp | |
end | |
return rand_seq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
稳定的多维条件数组排序 | |
由调用者保证tbCondition的元素个数大于等于维度nDimension | |
]] | |
function MutilArraySort(tbCondition, nDimension) | |
local tbResult = {} | |
for i = 1, #tbCondition do | |
local nInsert = 0 | |
local nLocal = 1 | |
for k = 1, nDimension do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[字典递增生成全排列,除去打印处理,只能说是效率低下,虽然核心程序只有12行,比较简洁]] | |
g_tbtest = {1,2,3} | |
function printTable(...) | |
local str = "" | |
local tbArgs = {...} | |
for i, tbStr in ipairs(tbArgs) do | |
if type(tbStr) == "table" then | |
for k, v in ipairs(tbStr) do | |
str = str..v |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function my_trim(szText) | |
{ | |
var str = szText; | |
var cleanStr = ""; | |
whitespace = ' /n/r/t/f/x0b/xa0/u2000/u2001/u2002/u2003/u2004/u2005/u2006/u2007/u2008/u2009/u200a/u200b/u2028/u2029/u3000'; | |
for (var i = 0; i < str.length; ++i) | |
{ | |
if (whitespace.indexOf(str.charAt(i)) === -1) | |
{ | |
cleanStr += str.charAt(i); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--分割字符串 | |
function sf_Split(str, splitor, nMatchModel) | |
splitor = splitor or ',' | |
nMatchModel = nMatchModel or true | |
local strArray = {} | |
local nStart = 1 | |
local splitorLen = string.len(splitor) | |
local index = string.find(str, splitor, nStart, nMatchModel) | |
while index do | |
strArray[#strArray + 1] = string.sub(str, nStart, index - 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO test_tong VALUES | |
("aaa", 9), ("asdf", 9), ("bbb", 9) | |
ON DUPLICATE KEY UPDATE | |
score = VALUES(score) | |
UPDATE test_tong SET | |
score = CASE tongname | |
WHEN "aaa" THEN 1 |
OlderNewer