diff options
| author | Abigail <abigail@abigail.be> | 2021-07-28 15:53:40 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-07-28 16:09:38 +0200 |
| commit | bd9797e1d52dc5b0853bc5400f04f477ffd6a4cb (patch) | |
| tree | 576c67d4bd3635f7a11b78180d4c569eabd167ea /challenge-123/abigail/lua | |
| parent | e604addad68c72201f22c43a611787e06983d7e9 (diff) | |
| download | perlweeklychallenge-club-bd9797e1d52dc5b0853bc5400f04f477ffd6a4cb.tar.gz perlweeklychallenge-club-bd9797e1d52dc5b0853bc5400f04f477ffd6a4cb.tar.bz2 perlweeklychallenge-club-bd9797e1d52dc5b0853bc5400f04f477ffd6a4cb.zip | |
Solutions in 15 languages for week 123, part 2.
Diffstat (limited to 'challenge-123/abigail/lua')
| -rw-r--r-- | challenge-123/abigail/lua/ch-2.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-123/abigail/lua/ch-2.lua b/challenge-123/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..b379f3078a --- /dev/null +++ b/challenge-123/abigail/lua/ch-2.lua @@ -0,0 +1,30 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-2.lua < input-file +-- + +local pat = "(-?%d+)"; +for _ = 2, 8 do + pat = pat .. "%s+(-?%d+)"; +end + + +for line in io . lines () do + _, _, x1, y1, x2, y2, x3, y3, x4, y4 = line : find (pat) + local e1 = (x1 - x2) ^ 2 + (y1 - y2) ^ 2 + local e2 = (x2 - x3) ^ 2 + (y2 - y3) ^ 2 + local e3 = (x3 - x4) ^ 2 + (y3 - y4) ^ 2 + local e4 = (x4 - x1) ^ 2 + (y4 - y1) ^ 2 + local d1 = (x1 - x3) ^ 2 + (y1 - y3) ^ 2 + local d2 = (x2 - x4) ^ 2 + (y2 - y4) ^ 2 + if e1 == e2 and e2 == e3 and e3 == e4 and d1 == d2 then + print (1) + else + print (0) + end +end |
