aboutsummaryrefslogtreecommitdiff
path: root/challenge-241/deadmarshal/lua/ch-1.lua
blob: a63054cda6486c7f9fa47da98d6a6859920e81cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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))