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/pascal | |
| 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/pascal')
| -rw-r--r-- | challenge-123/abigail/pascal/ch-2.p | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/challenge-123/abigail/pascal/ch-2.p b/challenge-123/abigail/pascal/ch-2.p index d71fa1c2f0..3bd63c819a 100644 --- a/challenge-123/abigail/pascal/ch-2.p +++ b/challenge-123/abigail/pascal/ch-2.p @@ -8,20 +8,21 @@ Program IsSquare; (* Run as: fpc -och-2.out ch-2.p; ./ch-2.out < input-file *) (* *) +function dist (x1, y1, x2, y2: integer): integer; +begin + dist := (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) +end; + var x1, y1, x2, y2, x3, y3, x4, y4: integer; - e1, e2, e3, e4, d1, d2: integer; begin while not eof () do begin readln (x1, y1, x2, y2, x3, y3, x4, y4); - e1 := (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); - e2 := (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3); - e3 := (x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4); - e4 := (x4 - x1) * (x4 - x1) + (y4 - y1) * (y4 - y1); - d1 := (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3); - d2 := (x2 - x4) * (x2 - x4) + (y2 - y4) * (y2 - y4); - if (e1 = e2) and (e2 = e3) and (e3 = e4) and (d1 = d2) then begin + if (dist (x1, y1, x2, y2) = dist (x2, y2, x3, y3)) and + (dist (x2, y2, x3, y3) = dist (x3, y3, x4, y4)) and + (dist (x3, y3, x4, y4) = dist (x4, y4, x1, y1)) and + (dist (x1, y1, x3, y3) = dist (x2, y2, x4, y4)) then begin writeln (1); end else begin |
