diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-07-06 18:59:05 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-07-06 18:59:05 -0400 |
| commit | fd818bbed60431914e34ed19fefc91a41b58014a (patch) | |
| tree | 3b520eda8bec5bd356bc9129656aad2a596c0724 /challenge-116 | |
| parent | 67db46384e0a113827d82b1383ee17f0ab4b9de6 (diff) | |
| download | perlweeklychallenge-club-fd818bbed60431914e34ed19fefc91a41b58014a.tar.gz perlweeklychallenge-club-fd818bbed60431914e34ed19fefc91a41b58014a.tar.bz2 perlweeklychallenge-club-fd818bbed60431914e34ed19fefc91a41b58014a.zip | |
1st commit on 116_lua
Diffstat (limited to 'challenge-116')
| -rwxr-xr-x | challenge-116/stuart-little/lua/ch-1.lua | 23 | ||||
| -rwxr-xr-x | challenge-116/stuart-little/lua/ch-2.lua | 9 |
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-116/stuart-little/lua/ch-1.lua b/challenge-116/stuart-little/lua/ch-1.lua new file mode 100755 index 0000000000..810c543ce1 --- /dev/null +++ b/challenge-116/stuart-little/lua/ch-1.lua @@ -0,0 +1,23 @@ +#!/usr/bin/env lua + +-- run <script> <number> + +function canSplit(lrg,sml) + rest = lrg:match(sml .. "(.*)") + if not rest then + return nil + end + if lrg == sml then + return lrg + end + nextIt = canSplit(rest,("%d"):format(sml+1)) + return nextIt and sml .. ", " .. nextIt or nil +end + +for i=1,arg[1]:len() do + res = canSplit(arg[1],arg[1]:sub(1,i)) + if res then + print(res) + os.exit() + end +end diff --git a/challenge-116/stuart-little/lua/ch-2.lua b/challenge-116/stuart-little/lua/ch-2.lua new file mode 100755 index 0000000000..75ac587ae2 --- /dev/null +++ b/challenge-116/stuart-little/lua/ch-2.lua @@ -0,0 +1,9 @@ +#!/usr/bin/env lua + +-- run <script> <number> + +sm=0 +for i = 1,arg[1]:len() do + sm = sm + arg[1]:sub(i,i)^2 +end +print(math.sqrt(sm) == math.floor(math.sqrt(sm)) and 1 or 0) |
