Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Project Ideas (http://www.programmingforums.org/forum50.html)
-   -   5d (http://www.programmingforums.org/showthread.php?t=887)

dnathe4th Oct 17th, 2004 12:37 PM

What would the easiest way to go about scripting, or writing a program, that output all the (positive) solutions to a 5dimensional problem?
for instance:
(1/2)A + (1/4)B + (1/8)C + (1/16)D + (1/32)E = 1/2

Ooble Oct 17th, 2004 2:13 PM

I take it you mean (1/2)x + (1/4)x + (1/8)x + (1/16)x + (1/32)x = 1/2. The solution is to parse it into some sort of array or something that holds all the info, and then rearrange the equation I know this doesn't really help, but there's more ;). Apparently Perl is brilliant for this sort of thing - look it up.

dnathe4th Oct 17th, 2004 2:36 PM

I used different letters rather than "X" because each variable needs to be different based on the coefficient. I'll get back to this post once i work it out

Ooble Oct 17th, 2004 4:36 PM

Ah... you mean ax^5 + bx^4 + cx^3 + dx^2 + ex = 0? I see... sounds complicated...

Ade Oct 17th, 2004 4:44 PM

may i ask why you need this?

dnathe4th Oct 17th, 2004 8:24 PM

Ooble, i mean as in :
(1/2)A + (1/4)B + (1/8)C + (1/16)D + (1/32)E = 1/2
as stated in my first post :P

Ade: It was a homework assignment for my brother (he's 12, i think they were just supposed to guess the answer), and being the programming dood i am, i wanted to figure out if it could be done by a program, since most things can, but i didn't know where to start, so i came here

Ooble Oct 18th, 2004 11:02 AM

Heh... sorry. That's my mind twisting things until they bear no resemblance to the original for ya.... be glad I'm not malicious :P

Pizentios Oct 18th, 2004 4:39 PM

What Class? Pre-Calc? Or Calc?

Mjordan2nd Oct 18th, 2004 4:56 PM

I'm guessing you mean all integers for values A, B, C, D, E. I just limited this to a 10 due to time constraints. I'm not sure this is what you want, but run this and tell me:

:

#include <stdio.h>
                                                       
int main(void)
{
    int a, b, c, d, e;
    FILE *fp;
    fp=fopen("answers.dat", "w+");
    for(a = 0; a<10; a++)
    {
        for(b=0; b<10; b++)
        {
            for(c=0; c<10; c++)
            {
                for(d=0;d<10;d++)
                {
                    for(e=0;e<10;e++)
                    {
                        if(((.5*a) + (.25 * b) + (.125 * c) + (.0625 * d) + (.03125 * e)) == .5)
                        {
                            fprintf(fp, "a=%d\nb=%d\nc=%d\nd=%d\ne=%d\n\n", a, b, c, d, e);
                        }
                    }
                }
            }
        }
    }
                                                       
    return 0;
}


Ade Oct 19th, 2004 4:05 PM

This all brings back painful memoriesof A-level math


All times are GMT -5. The time now is 1:07 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC