Thread: Finding the algorithm that's right for you.

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912

    Finding the algorithm that's right for you.

    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.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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

  3. #3
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    A post in straight C from me... don't get these so often . It's a simple function you want.

    Code:
    #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;
    }
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    The annoying thing is, as soon as I logged off after posting this, I figured it out. Murphy's Law I guess.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help on finding a better algorithm
    By Masterx in forum C Programming
    Replies: 15
    Last Post: 05-31-2009, 12:41 PM
  2. Need help finding a simple 'shortest path' algorithm
    By ashley in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 12:38 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM