diff options
Diffstat (limited to 'challenge-067/stuart-little/lua/ch-1.lua')
| -rwxr-xr-x | challenge-067/stuart-little/lua/ch-1.lua | 35 |
1 files changed, 35 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 |
