Alice Community  

Go Back   Alice Community > Alice 2 > Share Worlds

Reply
 
Thread Tools Display Modes
Pythagorean Triples
Old
bjia56
Guest
 
Status:
Posts: n/a
Cool Pythagorean Triples - 04-09-2010, 08:31 AM

Hey everyone,

While in class I made a program that calculates Pythagorean Triples from 1 to 100 in C++. I recently "converted" it into Alice, but it runs extremely slow, so it runs from 1 to 10 (or else takes forever to come up with the first triple).

It's kinda useless, but who knows, maybe someone will find a use for it.

C++ code:

Code:
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    double x;
    double y;
    double z;

    for (double a = 1; a <= 100; a++)
    {
        for (double b = 1; b <= 100; b++)
        {
            for (double c = 1; c <= 100; c++)
            {
                x = pow(a, 2);
                y = pow(b, 2);
                z = pow(c, 2);

                if (x + y == z)
                {
                    cout << "(" << a << "," << b << "," << c << ")" << endl;
                }
            }
        }
    }

return 0;

}
Attached Files
File Type: a2w Alice Pythagorean Theorem.a2w (39.7 KB, 16 views)
   
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.