diff options
| author | deadmarshal <adeadmarshal@gmail.com> | 2024-07-20 08:51:23 +0330 |
|---|---|---|
| committer | deadmarshal <adeadmarshal@gmail.com> | 2024-07-20 08:51:23 +0330 |
| commit | 83c26b915df95865c54062ab5c1a04a916ac217a (patch) | |
| tree | 01babe5709ac5289c13853e20cc52a487e0e1347 /challenge-278/deadmarshal/lua/ch-2.lua | |
| parent | 1e7c50d9232dcc1ca985e29ba4860aaf13725056 (diff) | |
| download | perlweeklychallenge-club-83c26b915df95865c54062ab5c1a04a916ac217a.tar.gz perlweeklychallenge-club-83c26b915df95865c54062ab5c1a04a916ac217a.tar.bz2 perlweeklychallenge-club-83c26b915df95865c54062ab5c1a04a916ac217a.zip | |
TWC278
Diffstat (limited to 'challenge-278/deadmarshal/lua/ch-2.lua')
| -rw-r--r-- | challenge-278/deadmarshal/lua/ch-2.lua | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/challenge-278/deadmarshal/lua/ch-2.lua b/challenge-278/deadmarshal/lua/ch-2.lua new file mode 100644 index 0000000000..d368132923 --- /dev/null +++ b/challenge-278/deadmarshal/lua/ch-2.lua @@ -0,0 +1,16 @@ +#!/usr/bin/env lua + +local function reverse_string(s,e) + assert(type(s) == 'string' and + type(e) == 'string','s and e must be strings!') + local t,idx = {},string.find(s,e,1,true) + if idx == nil then return s end + for i=1,idx do t[#t+1] = s:sub(i,i) end + table.sort(t) + return table.concat(t,'') .. s:sub(idx+1,#s) +end + +print(reverse_string('challenge','e')) +print(reverse_string('programming','a')) +print(reverse_string('champion','b')) + |
