aboutsummaryrefslogtreecommitdiff
path: root/challenge-123/abigail/node/ch-2.js
blob: 8e5fdb499ee86c8601a7d6215fff704936811e7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/local/bin/node

//
// See ../README.md
//

//
// 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 (_ => +_)
    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)
})