diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-07-14 22:12:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-14 22:12:28 +0100 |
| commit | 5cca639e7de20a3e1e1e12b545505f20ddcd92bb (patch) | |
| tree | 1c7d67811bbd0948625c821c4a5ea456baee430f | |
| parent | 273b446fb3e363c113fc4c4e6eec0e2d04aacbba (diff) | |
| parent | c6ffad84d3a1ef60c3ad8c1654a0fe1810f41e20 (diff) | |
| download | perlweeklychallenge-club-5cca639e7de20a3e1e1e12b545505f20ddcd92bb.tar.gz perlweeklychallenge-club-5cca639e7de20a3e1e1e12b545505f20ddcd92bb.tar.bz2 perlweeklychallenge-club-5cca639e7de20a3e1e1e12b545505f20ddcd92bb.zip | |
Merge pull request #4520 from stuart-little/stuart-little_088_lua
1st commit on 088_lua
| -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)) |
