Created
December 1, 2011 09:10
-
-
Save arch-jslin/1415217 to your computer and use it in GitHub Desktop.
misspell.lua
This file contains 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
local input = arg[1] | |
math.randomseed(os.time()) | |
local function random(n) return math.floor(math.random()*n) end | |
local function chararray(w) | |
local t = {}; | |
for i = 1, #w do t[i] = w:sub(i,i) end | |
return t | |
end | |
local function misspell(w) | |
local t = chararray(w) | |
for i = 2, #t-1 do | |
local dest = random(#t-i-2) + i + 1 | |
t[i], t[dest] = t[dest], t[i] | |
end | |
return table.concat(t, "") | |
end | |
local output = input:gsub("%w+", function(w) | |
if #w > 3 then | |
return misspell(w) | |
end | |
return w | |
end) | |
print "----------------------------" | |
print(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment