diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-02-16 10:32:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-16 10:32:33 +0000 |
| commit | 7c480291e4a71e4320fc98553de21c9eb47058c8 (patch) | |
| tree | 88ec6352c250c5653550dec54fb15984523b022d /challenge-152/abigail/lua/ch-2.lua | |
| parent | 348df89f110c0cc8654bc7ef97e1960e96c57ef2 (diff) | |
| parent | d6bba8467dbed369a17a8c8924d4cf51de6563b6 (diff) | |
| download | perlweeklychallenge-club-7c480291e4a71e4320fc98553de21c9eb47058c8.tar.gz perlweeklychallenge-club-7c480291e4a71e4320fc98553de21c9eb47058c8.tar.bz2 perlweeklychallenge-club-7c480291e4a71e4320fc98553de21c9eb47058c8.zip | |
Merge pull request #5658 from Abigail/abigail/week-152
Week 152: Solutions in 8 languages.
Diffstat (limited to 'challenge-152/abigail/lua/ch-2.lua')
| -rw-r--r-- | challenge-152/abigail/lua/ch-2.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-152/abigail/lua/ch-2.lua b/challenge-152/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..d7a0f6f594 --- /dev/null +++ b/challenge-152/abigail/lua/ch-2.lua @@ -0,0 +1,29 @@ +#!/opt/local/bin/lua + +-- +-- See https://theweeklychallenge.org/blog/perl-weekly-challenge-152 +-- + +-- +-- Run as: lua ch-2.lua < input-file +-- + +local i_pat = "(-?%d+)" +local pattern = i_pat +for i = 2, 8 do + pattern = pattern .. "%s+" .. i_pat +end + +for line in io . lines () do + local _, _, a_x1, a_y1, a_x2, a_y2, b_x1, b_y1, b_x2, b_y2 = + line : find (pattern) + print ( (math . max (a_x1, a_x2) - math . min (a_x1, a_x2)) * + (math . max (a_y1, a_y2) - math . min (a_y1, a_y2)) + + (math . max (b_x1, b_x2) - math . min (b_x1, b_x2)) * + (math . max (b_y1, b_y2) - math . min (b_y1, b_y2)) - +math . max (0, math . min (math . max (a_x1, a_x2), math . max (b_x1, b_x2)) - + math . max (math . min (a_x1, a_x2), math . min (b_x1, b_x2))) * +math . max (0, math . min (math . max (a_y1, a_y2), math . max (b_y1, b_y2)) - + math . max (math . min (a_y1, a_y2), math . min (b_y1, b_y2)))) + +end |
