diff options
| author | Abigail <abigail@abigail.be> | 2021-07-28 18:13:24 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-07-28 18:13:24 +0200 |
| commit | a42addb6a561d57e470cfed7828109bbfba040fb (patch) | |
| tree | c18527120e6a1f8a71e04910bc03ccc7d1e5fffa /challenge-123/abigail/node/ch-2.js | |
| parent | bd9797e1d52dc5b0853bc5400f04f477ffd6a4cb (diff) | |
| download | perlweeklychallenge-club-a42addb6a561d57e470cfed7828109bbfba040fb.tar.gz perlweeklychallenge-club-a42addb6a561d57e470cfed7828109bbfba040fb.tar.bz2 perlweeklychallenge-club-a42addb6a561d57e470cfed7828109bbfba040fb.zip | |
Use methods to factor out calculations.
Diffstat (limited to 'challenge-123/abigail/node/ch-2.js')
| -rw-r--r-- | challenge-123/abigail/node/ch-2.js | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/challenge-123/abigail/node/ch-2.js b/challenge-123/abigail/node/ch-2.js index 85ec5ce186..8e5fdb499e 100644 --- a/challenge-123/abigail/node/ch-2.js +++ b/challenge-123/abigail/node/ch-2.js @@ -8,15 +8,16 @@ // Run as: node ch-2.js < input-file // +function dist (x1, y1, x2, y2) { + return (x1 - x2) ** 2 + (y1 - y2) ** 2 +} + require ('readline') . createInterface ({input: process . stdin}) . on ('line', line => { let [x1, y1, x2, y2, x3, y3, x4, y4] = line . split (/ +/) . map (_ => +_) - let e1 = (x1 - x2) ** 2 + (y1 - y2) ** 2 - let e2 = (x2 - x3) ** 2 + (y2 - y3) ** 2 - let e3 = (x3 - x4) ** 2 + (y3 - y4) ** 2 - let e4 = (x4 - x1) ** 2 + (y4 - y1) ** 2 - let d1 = (x1 - x3) ** 2 + (y1 - y3) ** 2 - let d2 = (x2 - x4) ** 2 + (y2 - y4) ** 2 - console . log (e1 == e2 && e2 == e3 && e3 == e4 && d1 == d2 ? 1 : 0) + console . log (dist (x1, y1, x2, y2) == dist (x2, y2, x3, y3) && + dist (x2, y2, x3, y3) == dist (x3, y3, x4, y4) && + dist (x3, y3, x4, y4) == dist (x4, y4, x1, y1) && + dist (x1, y1, x3, y3) == dist (x2, y2, x4, y4) ? 1 : 0) }) |
