24 lines
794 B
Lua
24 lines
794 B
Lua
-- The hamming distance is the number of positions in which two
|
|
-- strings differ, and is used to measure how similar strings are.
|
|
-- Implement the hamming_distance() function below to calculate this;
|
|
-- you may assume that the strings are of equal length.
|
|
--
|
|
-- Solution --------------------------------------------------------------------
|
|
function hamming_distance(str1, str2)
|
|
-- Your implementation here
|
|
end
|
|
|
|
-- Tests -----------------------------------------------------------------------
|
|
|
|
local luaunit = require("luaunit.luauint")
|
|
|
|
function test_distance_between_foo_and_bar_is_3()
|
|
luaunit.assertEquals(hamming_distance("foo", "bar"), 3)
|
|
end
|
|
|
|
function test_distance_between_bar_and_baz_is_1()
|
|
luaunit.assertEquals(hamming_distance("bar", "baz"), 1)
|
|
end
|
|
|
|
os.exit(luaunit.LuaUnit.run())
|