[CHALLENGE] Find Rectangle from coordinates | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 25

[CHALLENGE] Find Rectangle from coordinates

Write a program that finds rectangles from a given set of coordinates. All languages welcome! Example: P0(2,2) P1(2,4) P2(2,6) P3(4,2) P4(4,4) P5(4,6) P6(6,0) P7(6,4) P8(8,2) P9(8,4) There are 6 rectangles: P0+P1+P4+P3 P0+P2+P5+P3 P1+P2+P5+P4 P0+P1+P9+P8 P3+P4+P9+P8 P3+P7+P8+P6 Here is my try in Java: https://code.sololearn.com/cbehADWNkNjT/#java

30th Jan 2018, 1:09 PM
Corey
Corey - avatar
8 Answers
+ 10
i see 9 rectangles.p0 p5 p9 p6 not in your list... https://code.sololearn.com/cCta1W7VT6PA/?ref=app
30th Jan 2018, 4:37 PM
VcC
VcC - avatar
30th Jan 2018, 9:23 PM
Med Arezki
Med Arezki - avatar
+ 7
This is a mission for OnelinerMan !
30th Jan 2018, 1:38 PM
VcC
VcC - avatar
+ 5
logic applied :- if slope of opposite sides is same and one of the angle is 90, It is rectangle...i found 9..thanks to @VcC for idea https://code.sololearn.com/cJb84vl04l5Q/?ref=app
3rd Feb 2018, 8:11 AM
Zoetic_Zeel
Zoetic_Zeel - avatar
+ 4
@Adam Ross (R055A) Yes, as I mentioned, the code is not really finished, that's right, the rectangle coordinates must exist in your inputs, the program will try until it finds the four coordinates, and also the satisfaction of having a rectangle parallel to the axes, I I'll try to fix that, thanks. Example : 8 -5 3 6 5 5 3 8 4 -5 -7 0 4 5 -7 0 0 The coordinates : (-5,3) (5,3) (-5,-7) (5,-7)
31st Jan 2018, 9:19 AM
Med Arezki
Med Arezki - avatar
+ 4
Yes ! the square angle, the code must have some changes, thanks. Nice code.
31st Jan 2018, 9:56 AM
Med Arezki
Med Arezki - avatar
+ 2
@med look at my code. a rectangle has sides which are parallel and of same length and a square angle. i added comments to my code
31st Jan 2018, 9:43 AM
VcC
VcC - avatar
+ 2
Got it: https://code.sololearn.com/ckX3xIu9vBMd/#py In my code, basically, I take advantage of the fact that rectangles, have two pairs of parallel sides. That's It! *Edit: Also made one in c++, just for the hardcore coders that want to understand it in their favourite languaje! https://code.sololearn.com/csrOHBHvtnq4/#cpp -Have a great day!
2nd Feb 2018, 7:12 PM
Brian
Brian - avatar