aboutsummaryrefslogtreecommitdiff
path: root/challenge-198/deadmarshal/lua/ch-1.lua
blob: 84837b45620aa80a4bf470ea79b12ced55c08754 (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 max_gap(t)
  local temp,count,max = 0,0,0
  if #t < 2 then return 0 end
  table.sort(t)
  for i=1,#t,2 do
    temp = math.abs(t[i] - t[i+1])
    if temp > max then max = temp end
  end
  for i=1, #t-1 do
    if math.abs(t[i] - t[i+1]) == max then count = count + 1 end
  end
  return count
end

print(max_gap({2,5,8,1}))
print(max_gap({3}))