aboutsummaryrefslogtreecommitdiff
path: root/challenge-215/deadmarshal/lua/ch-1.lua
blob: 33055f6bb1a20dda7955da9d6b31e7a7c6b25026 (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
#!/usr/bin/env lua

local function str_split(str)
  local res = {}
  str:gsub(".", function(c) table.insert(res,c) end)
  return res 
end
    
local function is_alphabetical_order(s)
  local t = str_split(s)
  for i=2,#t do
    if t[i] < t[i-1] then return false end
  end
  return true
end

local function odd_one_out(t)
  local count = 0
  for i=1,#t do
    if not is_alphabetical_order(t[i]) then count = count + 1 end
  end
  return count
end

print(odd_one_out({'abc', 'xyz', 'tsu'}))
print(odd_one_out({'rat', 'cab', 'dad'}))
print(odd_one_out({'x','y','z'}))