aboutsummaryrefslogtreecommitdiff
path: root/challenge-235/deadmarshal/lua/ch-1.lua
blob: 202fa877b4d14b9557f6c09bddc1b8bd0edc6904 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env lua

local function is_ascending(t)
  assert(type(t) == 'table','t must be a table!')
  local c = 1
  for i=1,#t-1 do
    if t[i] < t[i+1] then c = c + 1 end
  end
  return c == #t
end

local function remove_one(t)
  assert(type(t) == 'table','t must be a table!')
  local res = false
  for i=1,#t do
    local ret = {table.unpack(table.move(t,1,i-1,1,{})),
		 table.unpack(table.move(t,i+1,#t,1,{}))}
    if i == 1 then ret = table.move(t,2,#t,1,{})
    elseif i == #t then ret = table.move(t,1,#t-1,1,{})
    end
    if is_ascending(ret) then res = true end
  end
  return res
end

print(remove_one{0,2,9,4,5})
print(remove_one{5,1,3,2})
print(remove_one{2,2,3})