diff options
Diffstat (limited to 'challenge-067/stuart-little/lua/ch-2.lua')
| -rwxr-xr-x | challenge-067/stuart-little/lua/ch-2.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-067/stuart-little/lua/ch-2.lua b/challenge-067/stuart-little/lua/ch-2.lua new file mode 100755 index 0000000000..21a29b011e --- /dev/null +++ b/challenge-067/stuart-little/lua/ch-2.lua @@ -0,0 +1,32 @@ +#!/usr/bin/env lua + +-- run <script> <number> + +local dict={ + [0]="0", + "_@", + "abc", + "def", + "ghi", + "jkl", + "mno", + "pqrs", + "tuv", + "wxyz" +} + +function poss(dict,w) + if w:len()==0 then return {""} end + local prev=poss(dict,w:sub(1,-2)) + local out={} + for _,wrd in ipairs(prev) do + for i=1,string.len(dict[tonumber(w:sub(-1))]) do + table.insert(out,wrd..dict[tonumber(w:sub(-1))]:sub(i,i)) + end + end + return out +end + +for _,w in ipairs(poss(dict,arg[1])) do + print(w) +end |
