aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-07-18 17:18:48 +0100
committerGitHub <noreply@github.com>2021-07-18 17:18:48 +0100
commit1857a19609bd20d84e86e446c37516a06cad20d0 (patch)
tree9584f57bbe540e329743eee68f969f275cfd8b25
parent9206c4220e9f86992ebf843a9364fe3f1b279fa2 (diff)
parent10768c837cd2cfbd055be37509324fa20b904b22 (diff)
downloadperlweeklychallenge-club-1857a19609bd20d84e86e446c37516a06cad20d0.tar.gz
perlweeklychallenge-club-1857a19609bd20d84e86e446c37516a06cad20d0.tar.bz2
perlweeklychallenge-club-1857a19609bd20d84e86e446c37516a06cad20d0.zip
Merge pull request #4547 from stuart-little/stuart-little_067_lua
1st commit on 067_lua
-rwxr-xr-xchallenge-067/stuart-little/lua/ch-1.lua35
-rwxr-xr-xchallenge-067/stuart-little/lua/ch-2.lua32
2 files changed, 67 insertions, 0 deletions
diff --git a/challenge-067/stuart-little/lua/ch-1.lua b/challenge-067/stuart-little/lua/ch-1.lua
new file mode 100755
index 0000000000..fa38acbeba
--- /dev/null
+++ b/challenge-067/stuart-little/lua/ch-1.lua
@@ -0,0 +1,35 @@
+#!/usr/bin/env lua
+
+-- run <script> <m n> to get n-number combos from 1..m
+
+function comb(t)
+ local row={[0]={{}}}
+ for i=1,#t do
+ local tempRow={[0]={{}}}
+ for k=1,i do
+ local item={}
+ if (row[k]) then
+ for ix=1,#(row[k]) do
+ table.insert(item,row[k][ix])
+ end
+ end
+ for ixx=1,#(row[k-1]) do
+ local old=table.pack(table.unpack(row[k-1][ixx]))
+ table.insert(old,t[i])
+ table.insert(item,old)
+ end
+ table.insert(tempRow,item)
+ end
+ row=tempRow
+ end
+ return row
+end
+
+local t={}
+for i=1,arg[1] do
+ table.insert(t,i)
+end
+
+for _,v in ipairs(comb(t)[tonumber(arg[2])]) do
+ print(table.unpack(v))
+end
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