aboutsummaryrefslogtreecommitdiff
path: root/challenge-241/deadmarshal/lua/ch-1.lua
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-11-13 10:15:17 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-11-13 10:15:17 +0800
commit41f99d3c168e8def8c2a799c592282acf0d275a8 (patch)
treee862f32c73ecc3b39546d8f2e40268097bdc84eb /challenge-241/deadmarshal/lua/ch-1.lua
parent9831ad5b94643aec63e30e720b83dff7a5eac18b (diff)
parentf4d46d9aa21b95dbb99eec92f338d157273fbbdb (diff)
downloadperlweeklychallenge-club-41f99d3c168e8def8c2a799c592282acf0d275a8.tar.gz
perlweeklychallenge-club-41f99d3c168e8def8c2a799c592282acf0d275a8.tar.bz2
perlweeklychallenge-club-41f99d3c168e8def8c2a799c592282acf0d275a8.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-241/deadmarshal/lua/ch-1.lua')
-rw-r--r--challenge-241/deadmarshal/lua/ch-1.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-241/deadmarshal/lua/ch-1.lua b/challenge-241/deadmarshal/lua/ch-1.lua
new file mode 100644
index 0000000000..a63054cda6
--- /dev/null
+++ b/challenge-241/deadmarshal/lua/ch-1.lua
@@ -0,0 +1,19 @@
+#!/usr/bin/env lua
+
+local function arithmetic_triplets(t,diff)
+ local count = 0
+ for i=1,#t do
+ for j=i+1,#t do
+ for k=j+1,#t do
+ if t[j] - t[i] == diff and t[k] - t[j] == diff then
+ count = count + 1
+ end
+ end
+ end
+ end
+ return count
+end
+
+print(arithmetic_triplets({0,1,4,6,7,10},3))
+print(arithmetic_triplets({4,5,6,7,8,9},2))
+