That's an easy one. I just want to calculate the Hamming distance between two strings.
function hamming(str1,str2) local distance = 0 -- cannot calculate Hamming distance if strings have different sizes if #str1 ~= #str2 then return false end for i = 1, #str1 do if str1:sub(i,i) ~= str2:sub(i,i) then distance = distance + 1 end end return distance end
Maybe the for-loop isn't the most efficient one. I'm not sure. Any improvements?