Thread: Please help!!!

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Please help!!!


    I am trying to write a code to output a certain value (y) when given a value (x). It is something like as x increases by 1, y increases by the previous y value doubled. In other words, if x=2001 and y=32, when x=2002, y=64, when x=2003, y=128. How would I program something like this. Thanks.
  2. #2
  3. JavaScript is not spelt java
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2011
    Location
    Landan, England
    Posts
    743
    Rep Power
    165
    It is something like..
    You need to ask a specific question, and you also need to show the code that you have currently.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,893
    Rep Power
    481
    mathematically, given x0 and y0 you want to find y given x.

    It's perhaps
    y0 * 2 raised to the power of (x-x0)



    x0 is 2001
    y0 is 32

    what is y when x is 2003?

    32 * (2 raised to the power of (2003-2001))
    32 * 4 is 128

    The formula tests correctly.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    San Francisco Bay
    Posts
    1,939
    Rep Power
    1313
    Originally Posted by DHulse94
    It is something like as x increases by 1, y increases by the previous y value doubled.
    It is something like y = y0*2**(x-x0).

IMN logo majestic logo threadwatch logo seochat tools logo