diff options
| author | James Smith <baggy@baggy.me.uk> | 2021-07-28 08:28:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-28 08:28:52 +0100 |
| commit | f93588cc4c52a8b88c866417da6f347b32be49fb (patch) | |
| tree | e6164e734655d94708666bb68e708733da0b4d6d | |
| parent | eae557d6f630a37885ca460b4afad93f1656e715 (diff) | |
| download | perlweeklychallenge-club-f93588cc4c52a8b88c866417da6f347b32be49fb.tar.gz perlweeklychallenge-club-f93588cc4c52a8b88c866417da6f347b32be49fb.tar.bz2 perlweeklychallenge-club-f93588cc4c52a8b88c866417da6f347b32be49fb.zip | |
Update README.md
| -rw-r--r-- | challenge-123/james-smith/README.md | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/challenge-123/james-smith/README.md b/challenge-123/james-smith/README.md index 6954b8f076..c08cf498ff 100644 --- a/challenge-123/james-smith/README.md +++ b/challenge-123/james-smith/README.md @@ -109,7 +109,10 @@ benchmarks. ***You are given coordinates of four points i.e. (x1, y1), (x2, y2), (x3, y3) and (x4, y4). Write a script to find out if the given four points form a square.*** -## Solution. +## Assumption + +We will assume that the points are not in any particular order (The sequare may be p1->p2->p3->p4 OR p1->p3->p2->p4) +## Solution First we need to think how we define a square - it has 4 sides of equal length and sides at right angles. If we want to define it terms of distances between points we have 4 pairs of points that are the same distance apart and two pairs of points which are at `sqrt(2)` times this distance. @@ -117,7 +120,7 @@ First we need to think how we define a square - it has 4 sides of equal length a * an isosceles triangle with an inscribed equilateral triangle - the ratio of the two squares is `2+sqrt(3)` * a kite - for which one half is an equilateral triangle and the other has height `1-sqrt(3)/2` - the ratio of the two squares is `2-sqrt(3)`. - + We therefore measure the squares of the distances between the points, and collect them together. If the list of distances is 2, and the ratio of the squares of the distance is 2 then we have a square. |
