diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-07-14 03:18:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-14 03:18:34 +0100 |
| commit | c377c217590eaed53dde1ad03d9b80aa3c172429 (patch) | |
| tree | 335de9141bc2d2e3b374d37cddfa28b9ae6cd9eb | |
| parent | 7c7e0d2146fa109618f3de628786e2decd155042 (diff) | |
| parent | d76ed84ef4f923338dc685844519fe159da750e9 (diff) | |
| download | perlweeklychallenge-club-c377c217590eaed53dde1ad03d9b80aa3c172429.tar.gz perlweeklychallenge-club-c377c217590eaed53dde1ad03d9b80aa3c172429.tar.bz2 perlweeklychallenge-club-c377c217590eaed53dde1ad03d9b80aa3c172429.zip | |
Merge pull request #4512 from stuart-little/stuart-little_078_lua
1st commit on 078_lua
| -rwxr-xr-x | challenge-078/stuart-little/lua/ch-1.lua | 13 | ||||
| -rwxr-xr-x | challenge-078/stuart-little/lua/ch-2.lua | 16 |
2 files changed, 29 insertions, 0 deletions
diff --git a/challenge-078/stuart-little/lua/ch-1.lua b/challenge-078/stuart-little/lua/ch-1.lua new file mode 100755 index 0000000000..1b76fe7c70 --- /dev/null +++ b/challenge-078/stuart-little/lua/ch-1.lua @@ -0,0 +1,13 @@ +#!/usr/bin/env lua + +-- run <script> <space-separated numbers> + +local mx = tonumber(arg[#arg]) +local out = {mx} +for i=#arg-1,1,-1 do + if tonumber(arg[i]) > mx then + mx = tonumber(arg[i]) + table.insert(out,1,mx) + end +end +print(table.unpack(out)) diff --git a/challenge-078/stuart-little/lua/ch-2.lua b/challenge-078/stuart-little/lua/ch-2.lua new file mode 100755 index 0000000000..fd09ac713c --- /dev/null +++ b/challenge-078/stuart-little/lua/ch-2.lua @@ -0,0 +1,16 @@ +#!/usr/bin/env lua + +-- run <script> <space-separated array entries, then ' - ', then space-separated rotation indices> + +local nrs = {} +while (tonumber(arg[1])) do + table.insert(nrs,tonumber(arg[1])) + table.remove(arg,1) +end +table.remove(arg,1) +for _,v in ipairs(arg) do + local vv = (v-1)%#nrs+1 + local s=table.pack(table.unpack(nrs,vv+1)) + for i=1,vv do table.insert(s,nrs[i]) end + print(table.unpack(s)) +end |
