diff options
| -rwxr-xr-x | challenge-088/stuart-little/lua/ch-1.lua | 8 | ||||
| -rwxr-xr-x | challenge-088/stuart-little/lua/ch-2.lua | 44 |
2 files changed, 52 insertions, 0 deletions
diff --git a/challenge-088/stuart-little/lua/ch-1.lua b/challenge-088/stuart-little/lua/ch-1.lua new file mode 100755 index 0000000000..0efb408149 --- /dev/null +++ b/challenge-088/stuart-little/lua/ch-1.lua @@ -0,0 +1,8 @@ +#!/usr/bin/env lua + +-- run <script> <space-separated numbers> + +local prod,prods=1,{} +for _,v in ipairs(arg) do prod=prod*v end +for _,v in ipairs(arg) do table.insert(prods,("%d"):format(prod/v)) end +print(table.unpack(prods)) diff --git a/challenge-088/stuart-little/lua/ch-2.lua b/challenge-088/stuart-little/lua/ch-2.lua new file mode 100755 index 0000000000..b628715fd4 --- /dev/null +++ b/challenge-088/stuart-little/lua/ch-2.lua @@ -0,0 +1,44 @@ +#!/usr/bin/env lua + +--[[ +run <script> <path to file containing matrix> + +e.g. copy + + [ 1, 2, 3, 4 ] + [ 5, 6, 7, 8 ] + [ 9, 10, 11, 12 ] + [ 13, 14, 15, 16 ] + +to a text file and pass that file path +--]] + +function rot(t) + if #t==0 then return {} end + local rt={} + for i=#(t[1]),1,-1 do + local row={} + for j=1,#t do table.insert(row,t[j][i]) end + table.insert(rt,row) + end + return rt +end + +local mat={} + +for l in io.lines(arg[1]) do + local row={} + for n in l:gmatch("(%d+)") do table.insert(row,n) end + table.insert(mat,row) +end + +local out={} +repeat + local rng = table.remove(mat,1) + if rng then + for _,v in ipairs(rng) do table.insert(out,v) end + end + mat=rot(mat) +until not rng + +print(table.unpack(out)) |
