aboutsummaryrefslogtreecommitdiff
path: root/challenge-123/abigail/bash/ch-2.sh
blob: 68844b2f46140477724d525b9b7ea9745b432901 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh

#
# See ../README.md
#

#
# Run as: bash ch-2.sh < input-file
#

set -f

function dist () {((dist = ($1 - $3) ** 2 + ($2 - $4) ** 2))}

while read x1 y1 x2 y2 x3 y3 x4 y4
do    dist $x1 $y1 $x2 $y2; ((e1 = dist))
      dist $x2 $y2 $x3 $y3; ((e2 = dist))
      dist $x3 $y3 $x4 $y4; ((e3 = dist))
      dist $x4 $y4 $x1 $y1; ((e4 = dist))
      dist $x1 $y1 $x3 $y3; ((d1 = dist))
      dist $x2 $y2 $x4 $y4; ((d2 = dist))
      if ((e1 == e2 && e2 == e3 && e3 == e4 && d1 == d2))
      then echo 1
      else echo 0
      fi
done