aboutsummaryrefslogtreecommitdiff
path: root/challenge-228/roger-bell-west/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-228/roger-bell-west/lua/ch-2.lua')
-rwxr-xr-xchallenge-228/roger-bell-west/lua/ch-2.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/challenge-228/roger-bell-west/lua/ch-2.lua b/challenge-228/roger-bell-west/lua/ch-2.lua
new file mode 100755
index 0000000000..5b32f2d690
--- /dev/null
+++ b/challenge-228/roger-bell-west/lua/ch-2.lua
@@ -0,0 +1,34 @@
+#! /usr/bin/lua
+
+function emptyarray(a0)
+ local t = 0
+ local a = a0
+ while #a > 0 do
+ local mn = math.min(table.unpack(a))
+ for i, v in ipairs(a) do
+ if v == mn then
+ table.remove(a, i)
+ t = t + i
+ break
+ end
+ end
+ end
+ return t
+end
+
+
+
+if emptyarray({3, 4, 2}) == 5 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if emptyarray({1, 2, 3}) == 3 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+