aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-042/stuart-little/lua/ch-1.lua7
-rwxr-xr-xchallenge-042/stuart-little/lua/ch-2.lua26
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-042/stuart-little/lua/ch-1.lua b/challenge-042/stuart-little/lua/ch-1.lua
new file mode 100755
index 0000000000..9fe6a5c78c
--- /dev/null
+++ b/challenge-042/stuart-little/lua/ch-1.lua
@@ -0,0 +1,7 @@
+#!/usr/bin/env lua
+
+-- run <script> <largest decimal number to convert; defaults to 50>
+
+for n=0,(#arg>0 and tonumber(arg[1]) or 50) do
+ print(("Decimal: %d Octal: %o"):format(n,n))
+end
diff --git a/challenge-042/stuart-little/lua/ch-2.lua b/challenge-042/stuart-little/lua/ch-2.lua
new file mode 100755
index 0000000000..0b4af214a5
--- /dev/null
+++ b/challenge-042/stuart-little/lua/ch-2.lua
@@ -0,0 +1,26 @@
+#!/usr/bin/env lua
+
+-- run <script> <string or nothing to default to a random one>
+
+function bal(s)
+ local stk={}
+ for i=1,s:len() do
+ if #stk>0 and stk[#stk]=='(' and s:sub(i,i)==')'
+ then table.remove(stk)
+ else table.insert(stk,s:sub(i,i))
+ end
+ end
+ return (#stk==0) and 'OK' or 'NOT OK'
+end
+
+function genRndPars(n)
+ local s=""
+ for i=1,math.random(n) do
+ s=s..math.random(0,1)
+ end
+ return s:gsub(".",{['0']='(', ['1']=')'})
+end
+
+local s=#arg>0 and arg[1] or genRndPars(10)
+print(("Your string: %s"):format(s))
+print(bal(s))