aboutsummaryrefslogtreecommitdiff
path: root/challenge-152/abigail/node/ch-2.js
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-152/abigail/node/ch-2.js')
-rw-r--r--challenge-152/abigail/node/ch-2.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-152/abigail/node/ch-2.js b/challenge-152/abigail/node/ch-2.js
new file mode 100644
index 0000000000..c8b72f8786
--- /dev/null
+++ b/challenge-152/abigail/node/ch-2.js
@@ -0,0 +1,25 @@
+#!/usr/local/bin/node
+
+//
+// See https://theweeklychallenge.org/blog/perl-weekly-challenge-152
+//
+
+//
+// Run as: node ch-2.js < input-file
+//
+
+ require ('readline')
+. createInterface ({input: process . stdin})
+. on ('line', line => {
+ let [a_x1, a_y1, a_x2, a_y2, b_x1, b_y1, b_x2, b_y2] =
+ line . trim () . split (/ +/) . map (n => +n)
+ console . log ( (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))))
+
+})