diff options
| author | deadmarshal <adeadmarshal@gmail.com> | 2023-05-05 11:06:11 +0330 |
|---|---|---|
| committer | deadmarshal <adeadmarshal@gmail.com> | 2023-05-05 11:06:11 +0330 |
| commit | 15615cd21fe47b7e8c725521801c0dde7a024979 (patch) | |
| tree | e17d91edd3708012f9ea36616a8a77ad309373a9 /challenge-215/deadmarshal/lua/ch-1.lua | |
| parent | ca4fe9d2ded0e61630a63a53da7525a720c3d87a (diff) | |
| download | perlweeklychallenge-club-15615cd21fe47b7e8c725521801c0dde7a024979.tar.gz perlweeklychallenge-club-15615cd21fe47b7e8c725521801c0dde7a024979.tar.bz2 perlweeklychallenge-club-15615cd21fe47b7e8c725521801c0dde7a024979.zip | |
TWC215
Diffstat (limited to 'challenge-215/deadmarshal/lua/ch-1.lua')
| -rw-r--r-- | challenge-215/deadmarshal/lua/ch-1.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-215/deadmarshal/lua/ch-1.lua b/challenge-215/deadmarshal/lua/ch-1.lua new file mode 100644 index 0000000000..33055f6bb1 --- /dev/null +++ b/challenge-215/deadmarshal/lua/ch-1.lua @@ -0,0 +1,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'})) + |
