diff options
Diffstat (limited to 'challenge-111/stuart-little/lua/ch-2.lua')
| -rwxr-xr-x | challenge-111/stuart-little/lua/ch-2.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-111/stuart-little/lua/ch-2.lua b/challenge-111/stuart-little/lua/ch-2.lua new file mode 100755 index 0000000000..e4cd610499 --- /dev/null +++ b/challenge-111/stuart-little/lua/ch-2.lua @@ -0,0 +1,24 @@ +#!/usr/bin/env lua + +-- run <script> <file> + +local t={ln=0} + +function sorted(w) + local wt={} + for i in w:gmatch(".") do table.insert(wt,i) end + table.sort(wt) + return w==table.concat(wt) +end + +for l in io.lines(arg[1]) do + local w = l:match("%w+") + if sorted(w:lower()) and w:len() >= t['ln'] then + if w:len() > t['ln'] then t={ln=w:len()} end + table.insert(t,w) + end +end + +for _,v in ipairs(t) do + print(v) +end |
