diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-11-20 15:40:49 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-11-20 15:40:49 +0800 |
| commit | 72dc5412e640e26601ffdebc4f0247db4c4bc7fe (patch) | |
| tree | d405aa98925dfed0b745e5ec331e9498005b1de7 /challenge-243/deadmarshal/lua | |
| parent | 35d79358f3d12607da66ffefefed5e93c469d396 (diff) | |
| parent | fda51162ad0e1e8b4489fd2c73ef7dfdc8f0df5e (diff) | |
| download | perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.tar.gz perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.tar.bz2 perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-243/deadmarshal/lua')
| -rw-r--r-- | challenge-243/deadmarshal/lua/ch-1.lua | 16 | ||||
| -rw-r--r-- | challenge-243/deadmarshal/lua/ch-2.lua | 16 |
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-243/deadmarshal/lua/ch-1.lua b/challenge-243/deadmarshal/lua/ch-1.lua new file mode 100644 index 0000000000..7bb6d2ebaa --- /dev/null +++ b/challenge-243/deadmarshal/lua/ch-1.lua @@ -0,0 +1,16 @@ +#!/usr/bin/env lua + +local function reverse_pairs(t) + assert(type(t) == 'table','t must be a table!') + local count = 0 + for i=1,#t-1 do + for j=i+1,#t do + if t[i] > 2 * t[j] then count = count + 1 end + end + end + return count +end + +print(reverse_pairs{1,3,2,3,1}) +print(reverse_pairs{2,4,3,5,1}) + diff --git a/challenge-243/deadmarshal/lua/ch-2.lua b/challenge-243/deadmarshal/lua/ch-2.lua new file mode 100644 index 0000000000..c71dfcc814 --- /dev/null +++ b/challenge-243/deadmarshal/lua/ch-2.lua @@ -0,0 +1,16 @@ +#!/usr/bin/env lua + +local function floor_sum(t) + assert(type(t) == 'table','t must be a table!') + local sum = 0 + for i=1,#t do + for j=1,#t do + sum = sum + (t[i] // t[j]) + end + end + return sum +end + +print(floor_sum{2,5,9}) +print(floor_sum{7,7,7,7,7,7,7}) + |
