diff options
| author | E7-87-83 <fungcheokyin@gmail.com> | 2021-06-16 21:13:20 +0800 |
|---|---|---|
| committer | E7-87-83 <fungcheokyin@gmail.com> | 2021-06-16 21:13:20 +0800 |
| commit | 5e631f4b325d6ef41562ec1ef955e49e7da4ab75 (patch) | |
| tree | 77cd0ba501ebc5d0c0fcb36764e55c98b4869b3c /challenge-116/abigail/lua | |
| parent | 1dd7eedea237292a3fb563ecff37d004c3bbc772 (diff) | |
| parent | 0aa46d7e327eb82bd447279a1891f0d1873c46ff (diff) | |
| download | perlweeklychallenge-club-5e631f4b325d6ef41562ec1ef955e49e7da4ab75.tar.gz perlweeklychallenge-club-5e631f4b325d6ef41562ec1ef955e49e7da4ab75.tar.bz2 perlweeklychallenge-club-5e631f4b325d6ef41562ec1ef955e49e7da4ab75.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-116/abigail/lua')
| -rw-r--r-- | challenge-116/abigail/lua/ch-1.lua | 39 | ||||
| -rw-r--r-- | challenge-116/abigail/lua/ch-2.lua | 22 |
2 files changed, 61 insertions, 0 deletions
diff --git a/challenge-116/abigail/lua/ch-1.lua b/challenge-116/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..fadad776fa --- /dev/null +++ b/challenge-116/abigail/lua/ch-1.lua @@ -0,0 +1,39 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua < input-file +-- + +function make_sequence (string, start) + if string == start + then return start + end + if string : find ("^" .. start) + then tail = string : sub (#start + 1, -1) + result = make_sequence (tail, tostring (tonumber (start) + 1)) + if result ~= nil + then return start .. "," .. result + end + result = make_sequence (tail, tostring (tonumber (start) - 1)) + if result ~= nil + then return start .. "," .. result + end + end + return nil +end + +for line in io . lines () do + for i = 1, #line do + start = line : sub (1, i) + result = make_sequence (line, start) + if result ~= nil + then print (result) + goto end_main + end + end + ::end_main:: +end diff --git a/challenge-116/abigail/lua/ch-2.lua b/challenge-116/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..f53ea72076 --- /dev/null +++ b/challenge-116/abigail/lua/ch-2.lua @@ -0,0 +1,22 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-2.lua < input-file +-- + +for line in io . lines () do + local sum_of_squares = 0 + for d in line : gmatch ("%d") do + local number = tonumber (d) + sum_of_squares = sum_of_squares + number * number + end + root = math . floor (.5 + math . sqrt (sum_of_squares)) + if sum_of_squares == root * root + then print (1) + else print (0) + end +end |
