diff options
| author | Abigail <abigail@abigail.be> | 2021-06-07 20:10:04 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-06-08 15:47:36 +0200 |
| commit | 5f7b533e8cf34449a3a92a91dadc67856a883660 (patch) | |
| tree | 2623082bdb2d849d7a06388c00c9d02441d6a985 /challenge-116/abigail/lua/ch-2.lua | |
| parent | f08a13f3afd794045d93196c78b2c75f4959bd10 (diff) | |
| download | perlweeklychallenge-club-5f7b533e8cf34449a3a92a91dadc67856a883660.tar.gz perlweeklychallenge-club-5f7b533e8cf34449a3a92a91dadc67856a883660.tar.bz2 perlweeklychallenge-club-5f7b533e8cf34449a3a92a91dadc67856a883660.zip | |
AWK, Bash, C, Lua, Node.js, Perl, Python, Ruby solutions for week 116, part 2.
Diffstat (limited to 'challenge-116/abigail/lua/ch-2.lua')
| -rw-r--r-- | challenge-116/abigail/lua/ch-2.lua | 22 |
1 files changed, 22 insertions, 0 deletions
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 |
