Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Programming exercise

Name: Anonymous 2009-02-08 6:52

I recently found a website with multiple exercises to improve your logical thinking and programming at the same time, and I'm almost done with this one exercise, I'm just having problems with ONE small part. Now, it's not too important because I can simply move on to the next one, but it's bugging me and I'd like to find a way to solve it.

Quick description of the exercise:
You have a .txt with a bunch of random coordinates (x,y). Those coordinates are points for squares. Using the coordinates, you have to find out all of the possible squares and then print them out.

I have every algorithm done and programmed except the verification. Basically, what I'm trying to do is that once I've got my 4 points, I want a way to find out whether it's a square or not. I have a way that ``somewhat'' works, but it feels like a hack and I feel there should be a much simpler way.

bool isSquare(const Point& pt1, const Point& pt2, const Point& pt3, const Point& pt4){
}


What I'm doing right now is I calculate the distance (
float calculateDistance(const Point& pt1, const Point& pt2)
{
    float distance = 0.0;
    float deltaX = ((pt2.getX() - pt1.getX() * (pt2.getX() - pt1.getX())));
    float deltaY = ((pt2.getY() - pt1.getY() * (pt2.getY() - pt1.getY())));
    distance = sqrt(deltaX - deltaY);

    return distance;
}
) between pt1 and pt2, then check all the other sides. If I get two other sides of the same length => it's a side, if I get only one => it's a diagonal. I repeat that for combination of pt. At the end, if I get 4 sides and 2 diagonals, it's a square and then I add it to my end result vector. If not, I trash it.

Not urgent or anything, I'd just like to know whether anyone here has a better idea.

Name: Anonymous 2009-02-08 6:58

NO EXCEPTIONS

It's probably because you're using faggot next-line open braces

Name: Anonymous 2009-02-08 6:59

>>2
Your very manly and confident in you're sexuality.

Name: Anonymous 2009-02-08 7:01

>>3
no u

Name: Anonymous 2009-02-08 7:05

>>2
Oh you!

Actually, I'm using both in that post! I do need to make up my mind about it, though.

Name: Anonymous 2009-02-08 7:07

>>3
Please correct you're spelling.

Name: Anonymous 2009-02-08 8:38

Thinking about it, I realized all you really need is the two diagonals and it's 100% sure it'll be a square. Still don't know how to figure out how to calculate the diagonals with only 4 points in a random order.

Name: Anonymous 2009-02-08 9:01

>>7
s/the two diagonals/the two diagonals to be equal

Name: Anonymous 2009-02-08 9:04

Getters and setters always turns ordinary code into awesome OOP.

Name: Anonymous 2009-02-08 11:23

post link to original exercise

Name: Anonymous 2009-02-08 11:33

             diagonal 1
       \  /
        \/
        /\
       /  \
      /    \
     /      \
    /        \
   /          \
  /            \
 /              \
/                \
                   diagonal 2
                  
                  
        they are equal
  
hax my anus quality post

Name: Anonymous 2009-02-08 11:37

I solved this problem 5 days ago

Name: Anonymous 2009-02-08 12:31

Hint: if the 4 points A, B, C, D define a square, then
A c B
A c C
A c D
C c D
B c D


where A c B means that A and B are colinear.

Name: Anonymous 2009-02-08 14:30

Two points are always collinear.

Name: Anonymous 2009-02-08 14:42

>>14
Great! That means the function simplifies to return true.
This is easier than I thought.

Name: Anonymous 2009-02-08 16:41

what's the website OP?

Name: Anonymous 2009-02-08 16:41

Hint: c2 = a2 + b2

Name: Anonymous 2009-02-08 16:47

link to website please

Name: Anonymous 2009-02-08 17:01

OP here... still trying to work on it a bit. And no I'm not going to post a link because I don't want anyone here to become better than me at this. :)

Name: Anonymous 2009-02-08 17:12

>>13-15

(c) :: Point -> Point -> Bool
(c) a b = True

Name: Anonymous 2009-02-08 17:15

is this a project euler prob?  if so what numb?

Name: Anonymous 2009-02-08 18:06

>>21
Finish your fucking words, doucheb.

Name: Anonymous 2009-02-08 18:37

>>17
Fuck you, Pythagoras.

Name: Anonymous 2009-02-08 18:39

>>19
You're not OP. I'm OP. I found the solution a while ago.

Name: Anonymous 2009-02-08 18:53

>>24
OP here, I suck cocks for free.

Name: Anonymous 2009-02-08 18:59

>>25
OP here, It actually costs $5 or $10 for anal

Name: Anonymous 2009-02-08 19:08

This may surprise you but I invented the OP.

Name: OP 2009-02-08 19:12

>>27
This may OP you but I surprised the invention

Name: Anonymous 2009-02-08 19:19

>>28

This may invent you but I OPed the surprise.

Name: Anonymous 2009-02-08 19:20

OP may invent you but I surprised this.

Name: Anonymous 2009-02-09 7:23

This surprise may OP you but I invented.

Name: Anonymous 2009-02-09 8:09

>>22
no. im using a +optimzd english

Name: Anonymous 2009-02-09 12:28

>>32
Premature optimization.

Name: Anonymous 2009-02-09 23:26

>>33
You know, there's an immature in there somewhere.

Name: Anonymous 2010-12-06 9:35

Back to /b/, ``GNAA Faggot''

Don't change these.
Name: Email:
Entire Thread Thread List