aboutsummaryrefslogtreecommitdiff
path: root/challenge-239/deadmarshal/lua/ch-2.lua
blob: e4c7d15181e7d871ac3ad411d96816642d82efa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env lua

local function consistent_strings(t,allowed)
  assert(type(t) == 'table' and type(allowed) == 'string',
	 't,allowed must be a table and string respectively!')
  local count = 0
  for i=1,#t do
    local temp = true
    for j=1,#t[i] do
      if not allowed:match(t[i]:sub(j,j)) then temp = false break end
    end
    if temp == true then count = count + 1 end
  end
  return count
end

print(consistent_strings({'ad','bd','aaab','baa','badab'},'ab'))
print(consistent_strings({'a','b','c','ab','ac','bc','abc'},'aabc'))
print(consistent_strings({'cc','acd','b','ba','bac','bad','ac','d'},
	'cad'))