aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-07-15 22:03:10 +0100
committerGitHub <noreply@github.com>2021-07-15 22:03:10 +0100
commit6bdc8180249407e9355661d9b74aa7af7ea30ee0 (patch)
tree446b4bece389c221822e220a27ccea3f1383efae
parenta7e3a217f22b0060a44c0170bf78f77ae27fbe3f (diff)
parent1f0aac7d81b1b1ce7b0c9b07388996a64bff10ed (diff)
downloadperlweeklychallenge-club-6bdc8180249407e9355661d9b74aa7af7ea30ee0.tar.gz
perlweeklychallenge-club-6bdc8180249407e9355661d9b74aa7af7ea30ee0.tar.bz2
perlweeklychallenge-club-6bdc8180249407e9355661d9b74aa7af7ea30ee0.zip
Merge pull request #4527 from stuart-little/stuart-little_073_lua
1st commit on 073_lua
-rwxr-xr-xchallenge-073/stuart-little/lua/ch-1.lua21
-rwxr-xr-xchallenge-073/stuart-little/lua/ch-2.lua11
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-073/stuart-little/lua/ch-1.lua b/challenge-073/stuart-little/lua/ch-1.lua
new file mode 100755
index 0000000000..452c6f73c0
--- /dev/null
+++ b/challenge-073/stuart-little/lua/ch-1.lua
@@ -0,0 +1,21 @@
+#!/usr/bin/env lua
+
+-- run <script> <space-separated numbers, with the window size first>
+
+function slide(fn,t,k)
+ local out={}
+ for i=1,#t-k+1 do
+ table.insert(out,fn(table.unpack(t,i,i+k-1)))
+ end
+ return out
+end
+
+function map(fn,t)
+ local out={}
+ for _,v in ipairs(t) do
+ table.insert(out,fn(v))
+ end
+ return out
+end
+
+print(table.unpack(slide(math.min,map(tonumber,table.pack(table.unpack(arg,2))),tonumber(arg[1]))))
diff --git a/challenge-073/stuart-little/lua/ch-2.lua b/challenge-073/stuart-little/lua/ch-2.lua
new file mode 100755
index 0000000000..6b86f6e4e8
--- /dev/null
+++ b/challenge-073/stuart-little/lua/ch-2.lua
@@ -0,0 +1,11 @@
+#!/usr/bin/env lua
+
+-- run <script> <space-separated numbers>
+
+local out,run={}
+for k,v in ipairs(arg) do
+ table.insert(out,(((not run) and 0) or (tonumber(v)<=run and 0) or (run)))
+ run=run and run <= tonumber(v) and run or tonumber(v)
+end
+
+print(table.unpack(out))