diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-10-23 15:13:49 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-10-23 15:13:49 +0800 |
| commit | 595d92e7e979a5c6d56f128b0c2afe5ea84afda2 (patch) | |
| tree | 3d1398df34ec1afee608634b4ccf41d22fccf757 /challenge-239/deadmarshal/lua/ch-2.lua | |
| parent | f1bd3bd0a86630b6d6446edc68ff5035980bec0f (diff) | |
| parent | 67310476fd1daa9d74365ca666f4f6d9a0932d50 (diff) | |
| download | perlweeklychallenge-club-595d92e7e979a5c6d56f128b0c2afe5ea84afda2.tar.gz perlweeklychallenge-club-595d92e7e979a5c6d56f128b0c2afe5ea84afda2.tar.bz2 perlweeklychallenge-club-595d92e7e979a5c6d56f128b0c2afe5ea84afda2.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-239/deadmarshal/lua/ch-2.lua')
| -rw-r--r-- | challenge-239/deadmarshal/lua/ch-2.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-239/deadmarshal/lua/ch-2.lua b/challenge-239/deadmarshal/lua/ch-2.lua new file mode 100644 index 0000000000..e4c7d15181 --- /dev/null +++ b/challenge-239/deadmarshal/lua/ch-2.lua @@ -0,0 +1,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')) + |
