Thread: formula

  1. #1
    pete
    Guest

    formula

    Hi, I was just wondering if it is possible to take two numbers or digits, and process them in such a way in that the result will allow you to extract them two digits and/or numbers again.

    For example, say you have 31 and 49 and the result of the formula applied to them was 456. Is there a formula in existence that can be applied to them two numbers so you can get them back again?

    Thanks, for any feedback.

  2. #2
    pete
    Guest
    yes exactly thanks. Tell me, where did you learn that formula from? Is just experience in programming?

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    it depends on what your original formula is... it's just algebra... the reverse formula he gave you would only work for the original formula he used or a variation of that...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    Whats your initial formula

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    The simplest formula for two numbers, a and b, where a has a defined maximum value, would be
    Code:
    combinedValue = a + [ b * ( maxValue( a ) + 1 ) ]
    Then, to go the other way:
    Code:
    a = combinedValue modulo maxValue( a )
    b = floor( combinedValue / maxValue( a ) )
    Last edited by XSquared; 05-26-2003 at 08:04 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Of course, the most compact formula you can come up with to combine two distinct numbers and then retrieve them is XSquared's, but it suffers from the fact that it only works on bounded numbers, and can quite easily run into overflow problems.

    If you know one of them however,

    combined = x ^ y;
    ... and then ...
    x = combined ^ y; ... or ...
    y = combined ^ x;
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  7. #7
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Heh. I completely forgot about XORing things. In my opinion, its much, much better than my previously posted algorithm, because the combined value is always going to be within the data type's bounds.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  8. #8
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    if you wana get more complex you can have the first digit represent a key to the formula. which is applied during creation and is randomly created. that way you can realy have it hard to figure out. Again we just need your formula

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Zeller's Formula
    By unejam2005 in forum C++ Programming
    Replies: 6
    Last Post: 11-14-2005, 09:48 PM
  2. how to change char to formula
    By kosong in forum C Programming
    Replies: 2
    Last Post: 06-09-2003, 04:31 AM
  3. Math formula (js -->C++)
    By Demon1s in forum C++ Programming
    Replies: 20
    Last Post: 05-02-2003, 05:22 AM
  4. Need help with this formula -b/2a..Please read.
    By foofoo in forum C Programming
    Replies: 4
    Last Post: 06-04-2002, 11:59 PM
  5. Formula string conversion
    By Gr3g in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2002, 08:28 PM