PDA

View Full Version : Finding the algorithm that's right for you.



sean
02-02-2002, 01:48 PM
1 2 3 4 5 6 7 8 9 10
1 2 4 8 16 32 64 128 256 512

I need an equation that takes a number from the top row as it's only variable, and produces the corresponding number on the bottom. You can also move them around, like have 0 above the 2 or something, but just tell me which direction you moved which bar how far. I just need a starting point. i tried finding the differences but it just turns into circular logic.

Salem
02-02-2002, 02:08 PM
Well, if you had this

0 1 2 3 4 5 6 7 8 9 10
1 2 4 8 16 32 64 128 256 512

Then it's just pow(2,n)

Two, to the power of the number on the top row, gives you the number on the bottom row

SilentStrike
02-02-2002, 02:08 PM
A post in straight C from me... don't get these so often :). It's a simple function you want.



#include <stdio.h>

int main(int argc, char *argv[])
{
for (int i = 1; i < 11; i++) {
printf("Input is %i, output is is %i \n", i, 1 << (i - 1));
}
getchar();
return 0;
}

sean
02-03-2002, 10:03 AM
The annoying thing is, as soon as I logged off after posting this, I figured it out. Murphy's Law I guess.