aboutsummaryrefslogtreecommitdiff
path: root/challenge-228/deadmarshal/lua/ch-2.lua
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-08-07 15:12:39 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-08-07 15:12:39 +0800
commit6ef46b171c093a7fc72e6b52662b9020fe71753a (patch)
treec69b365edfce5a183ad3e2aeb9f667f8885c3589 /challenge-228/deadmarshal/lua/ch-2.lua
parentcb5bb2d77bf43ab282150372f5cd87bbbcb7a477 (diff)
parent2b2c6ec6ece04737ba9a572109d5e7072fdaa14a (diff)
downloadperlweeklychallenge-club-6ef46b171c093a7fc72e6b52662b9020fe71753a.tar.gz
perlweeklychallenge-club-6ef46b171c093a7fc72e6b52662b9020fe71753a.tar.bz2
perlweeklychallenge-club-6ef46b171c093a7fc72e6b52662b9020fe71753a.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-228/deadmarshal/lua/ch-2.lua')
-rw-r--r--challenge-228/deadmarshal/lua/ch-2.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/challenge-228/deadmarshal/lua/ch-2.lua b/challenge-228/deadmarshal/lua/ch-2.lua
new file mode 100644
index 0000000000..8f3245f208
--- /dev/null
+++ b/challenge-228/deadmarshal/lua/ch-2.lua
@@ -0,0 +1,15 @@
+#!/usr/bin/env lua
+
+local function empty_array(t)
+ local count = 0
+ while #t ~= 0 do
+ if t[1] == math.min(table.unpack(t)) then table.remove(t,1)
+ else table.insert(t,table.remove(t,1)) end
+ count = count + 1
+ end
+ return count
+end
+
+print(empty_array({3,4,2}))
+print(empty_array({1,2,3}))
+