From 74d32165e22ba78426bb61ccd79e600d2546f956 Mon Sep 17 00:00:00 2001 From: deadmarshal Date: Wed, 18 Oct 2023 21:48:51 +0330 Subject: TWC239 --- challenge-239/deadmarshal/lua/ch-2.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 challenge-239/deadmarshal/lua/ch-2.lua (limited to 'challenge-239/deadmarshal/lua/ch-2.lua') 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')) + -- cgit