• (cs) in reply to giannis
    Anonymous:
    Otto:

    This is true, but the correct response is not to point out x+=11 or even x=x+11, but you ask "Dude, are you high?" and try to score some of that phat dope that Nathan had been smoking.

    Because while I can perfectly well see somebody not knowing about += or even zoning out on it, I cannot see anybody, anywhere, ever being unable to grasp a simple x=x+11 statement.



    It is obvious that the guy new how to increment with x=x+11, he also rembered that there was an operator similar to x++ but didn't remember it exactly, so he asked his expert colleague. It's just a badly formed question.


    No, I think it is a case of a badly formed employee.
  • (cs) in reply to KraGiE
    KraGiE:
    Gene Wirchenko:
    Alex Papadimoulis:

    Another slow day, another revisited post. Even if you've seen the original, I highly recommend checking out the comments posted. There you will find a number of solutions (five pages worth) to the problem that Steve Local's ... less gifted ... colleague was having in C# ...

    Nathan: Steve, you know how ++ will increment, right?
    Steve: Right ....
    Nathan: Okay, so how do you increment by 11?



    You use +=.

    This is not a WTF.  It might even be the opposite.  Nathan may never have seen += for whatever reason, or it could be a brief zone-out.

    Sincerely,

    Gene Wirchenko

    /agreed.  The WTF is more to the OP that clearly isn't able to discern between ignorance and just lack of knowledge.  Better he asked than to try to come up with a solution that would have been a WTF.

    That is very humorous - "isn't able to discern between ignorance and just lack of knowledge" - neither can I, since they are the same thing! http://dictionary.reference.com/search?q=ignorance

  • (cs) in reply to flobi

    I submitted that php class I wrote to phpclasses.org to see if they'd actually accept a 150+ line class that just adds 2 numbers together...http://www.phpclasses.org/browse/package/2799.html  LOL!

  • jbange (unregistered) in reply to werewrwe
    Anonymous:
    KraGiE:

    /agreed.  The WTF is more to the OP that clearly isn't able to discern between ignorance and just lack of knowledge.  Better he asked than to try to come up with a solution that would have been a WTF.



    Even if he's never seen +=. He's probably i = i + 11... Which is the same thing...


    Clearly the issue is not that he'd never SEEN the += operator, but that he couldn't REMEMBER the += operator. He knew it existed (as it is essentially the "increment by" operator he's referring to), but didn't recall what it was. Noob behavior, to be sure, but not really "WTF"...
  • (cs)

    #define SIX 8 - 2 #define NINE 2 + 7

    x += SIX * NINE;

  • (cs)

    <FONT face=Verdana size=2>Well, of course it has to be:</FONT>

    <FONT face="Courier New">((((((((((i++)++)++)++)++)++)++)++)++)++)++</FONT>

    [:D]

  • (cs) in reply to Mystery
    Mystery:
    #define SIX 8 - 2
    #define NINE 2 + 7
    x += SIX * NINE;


    If you prefer something more canonical:

    <font size="2">     #define SIX 1+5
         #define NINE 8+1

         printf("%d", SIX*NINE);

    </font>
    Sincerely,

    Gene Wirchenko

  • (cs) in reply to Gene Wirchenko
    Gene Wirchenko:
    Mystery:
    #define SIX 8 - 2
    #define NINE 2 + 7
    x += SIX * NINE;


    If you prefer something more canonical:

    <font size="2">     #define SIX 1+5
         #define NINE 8+1

         printf("%d", SIX*NINE);
    </font>


    I'm sure you mean

    <font size="2">     #define NINE 8-1
    </font>
    Only then do you get the correct answer (though you may not like it). Even better:

    <font size="2">     #define l -2 // correction factor
         ...
    </font><font size="2">     #define NINE 8+l
    </font>


  • (cs) in reply to brazzy
    brazzy:
    Gene Wirchenko:
    Mystery:
    #define SIX 8 - 2
    #define NINE 2 + 7
    x += SIX * NINE;


    If you prefer something more canonical:

    <font size="2">     #define SIX 1+5
         #define NINE 8+1

         printf("%d", SIX*NINE);
    </font>

    I'm sure you mean

    <font size="2">     #define NINE 8-1
    </font>
    Only then do you get the correct answer (though you may not like it). Even better:

    <font size="2">     #define l -2 // correction factor
         ...
    </font><font size="2">     #define NINE 8+l
    </font>


    Nope.  My post stands.  Remember to do the substitution first and that there are no brackets.

    Sincerely,

    Gene Wirchenko

  • (cs) in reply to Gene Wirchenko
    Gene Wirchenko:
    Mystery:
    #define SIX 8 - 2
    #define NINE 2 + 7
    x += SIX * NINE;
    If you prefer something more canonical:
    Yeah, I was making reference to that. It still works in my case: forty-two (which equals six times nine) is the answer to the ultimate question of life, the universe, and everything. :-)
  • (cs) in reply to mgla
    mgla:

    <font face="Verdana" size="2">Well, of course it has to be:</font>

    <font face="Courier New">((((((((((i++)++)++)++)++)++)++)++)++)++)++</font>

    [:D]



    HA! N3wb! </1337> Now go look up the postincrementation rules! And then read MY _informed_ post above where I do it *correctly*! ;) :p
  • (cs) in reply to Gene Wirchenko
    Gene Wirchenko:

    Nope.  My post stands.  Remember to do the substitution first and that there are no brackets.


    Ah, serves me right for wandering unprepared into the murky depths of C preprocessor madness...
  • (cs) in reply to brazzy

    No one mentioned:

    #!/usr/bin/ruby
    i = 1
    11.times {i+=1}
    puts i

  • (cs) in reply to flobi

    flobi:
    I submitted that php class I wrote to phpclasses.org to see if they'd actually accept a 150+ line class that just adds 2 numbers together...http://www.phpclasses.org/browse/package/2799.html  LOL!

    Yeah... some poor beg's gonna see it and use it somewhere. Next thing ya know... it'll show up here.  But still, what a hoot.

  • house (unregistered) in reply to dhromed

    What about... x = x + 11.

    So damn simple.

  • Barruelix (unregistered) in reply to Mystery

    forty-two (which equals six times nine)

    WTF?
  • (cs) in reply to Barruelix
    Anonymous:

    forty-two (which equals six times nine)
    WTF?


    http://en.wikipedia.org/wiki/The_Answer_to_Life%2C_the_Universe%2C_and_Everything
  • (cs) in reply to Barruelix
    Anonymous:

    forty-two (which equals six times nine)

    WTF?
    Traceback (most recent call last): User "Anonymous/Barruelix", line 1, in -toplevel- WTF? GeekKnowledgeException: user doesn't know Douglas Adam

    Seriously, in that day and age and on this board, how's that possible?

  • (cs) in reply to RevMike

    Any technology sufficiently advanced is indistinguishable from a one-line Perl script:
    perl -e '$i = shift; eval q($i++;) x 11; print $i' 31

    (Windows users -- change the 's to "s)

  • (cs) in reply to Mikademus
    Mikademus:
    mgla:

    <FONT face=Verdana size=2>Well, of course it has to be:</FONT>

    <FONT face="Courier New">((((((((((i++)++)++)++)++)++)++)++)++)++)++</FONT>

    [:D]



    HA! N3wb! </1337>Now go look up the postincrementation rules! And then read MY _informed_ post above where I do it *correctly*! ;) :p

    Thank you for the kind words... [:#]

    Did you really think I meant this??? Too bad for you if you did...

  • (cs)

    I'm surprised no one has shown how easy this is in Ruby!

    11.times { i += 1 } i

  • mjc (unregistered) in reply to Otto

    except when i == 0 or (maybe) i < 0

  • (cs) in reply to mjc

    The following does not increment by 11:

    [code]
    var x = 1;

    for (var i = 0; i < 4; i++)
    {
    x += x
    }
    x -= 5

    alert(x)
    [/code[

  • (cs)

    int MyNumber;
    //assign some value to MyNumber here

    union PleaseIncreaseThisIntegerBy11
          {
           signed int number1;
           unsigned int number2;
          };

    PleaseIncreaseThisIntegerBy11 PrettyPlease;
    PrettyPlease.number2 = 4294967285;
    MyNumber -= PrettyPlease.number1;

  • anonymous coward (unregistered) in reply to Sammie

    Sorry to bring up an old post, but
    maybe  (excuse the lack of proper c# but i'm fairly lazy)
    sqlConnection sc=new sqlConnection ("blahblah blah server info blah blah");
    sc.open();
    for (int x=15; x>=5; --x)
    new sqlcommand("insert into tablep", sc).executenonquery();
    int ineed11=ineed11+int.parse(new sqlcommand("select count (*) from (select top 11 from tablep) q ", sc).executescalar().tostring())

    //sc.close()   //comment this out because closing connections is for chumps

  • John (unregistered) in reply to maht

    x = ((x/11)++)*11

  • (cs) in reply to John
    Anonymous:

    x = ((x/11)++)*11

    You'll need to cast it to a float for small numbers.

  • Noam Samuel (unregistered)

    Here's my addition to the heap of obfuscation seen here (this is in PHP, and was indeed verified to work):

    <?
    function add11to($i)
    {
    $i3 = $i; $i2 = $i;
    while ($i++ != $i2+count(file(FILE)) - 1){
    for($i4 = 0; $i4 <= $i2+count(file(FILE)) - 1; $i4++){
    if ($i4 == $i2+count(file(FILE)) - 1) $i3++;
    }
    }
    return $i3;
    }
    ?>

  • (cs) in reply to bobo1on1
    bobo1on1:
    Anonymous:

    x = ((x/11)++)*11

    You'll need to cast it to a float for small numbers.



    bobo1on1: Huh?

    Anonymous: (x/11) is not ++-able.  On either side.
  • John (unregistered) in reply to Maurits

    I was kinda replying to the comment about 'subtle floating point errors' from a previous page, sorry I wasn't more clear, and it should probably have been more like (x/11+1)*11 but I was too lazy to fire up a compiler...

    In compensation, here is an example, that if I recall correctly would have worked in GW Basic:

    x=x+(x=(x-11))*-11

     

  • (cs) in reply to John

    Oh, I see... I was thinking integer arithmetic.

  • boner (unregistered) in reply to Gene Wirchenko

        i += 11 - i;

  • (cs)
    Alex Papadimoulis:

    Another slow day, another revisited post. Even if you've seen the original, I highly recommend checking out the comments posted. There you will find a number of solutions (five pages worth) to the problem that Steve Local's ... less gifted ... colleague was having in C# ...

    Nathan: Steve, you know how ++ will increment, right?
    Steve: Right ....
    Nathan: Okay, so how do you increment by 11?

    ((var / 11.0)++) * 11.0

  • (cs) in reply to dhromed
    dhromed:
    I'd like to see some code that almost adds 11.

    Preferrably by introducing floating point errors.


    double incr = 1.0/3
    for (int c = 0; c < 33; c++) i += incr;

    1.0/3 == 0.33333333333333331482961625624739
    coudn't use the well known 1.0/10 because it would be slightly more (0.10000000000000000555111512312578) instead of less.
  • dvrvm (unregistered) in reply to Zom-B

    As you surely know, iteration is human, but recursion is godlike.
    Therefore, a much better way to increment i by 11 has to be implemented using recursion:

    public class SimpleAdderByEleven {
    private int add(int a, int b) throws Exception {
    if ((a<0) || (b<0))
    throw new Exception("Argument out of range");
    if (b>0)
    return add(increment(a),decrement(b));
    else
    return a;
    }
    public int incrementByEleven (int numberToBeIncrementedByEleven) throws Exception
    {
    try {
    return add(eleven(),numberToBeIncrementedByEleven);
    }
    catch(Exception e) {
    throw new Exception("Argument out of range");
    }
    }
    private int generateEleven(int elevenSeed) {
    if (elevenSeed < 11)
    return(generateEleven(++elevenSeed));
    else
    return 11;
    }
    private int eleven(){
    return generateEleven(0);
    }
    private int increment(int numberToBeIncremented) {
    numberToBeIncremented = numberToBeIncremented + (eleven() / eleven());
    return numberToBeIncremented;
    }
    private int decrement(int numberToBeDecremented) {
    numberToBeDecremented = numberToBeDecremented - (eleven() / eleven());
    return numberToBeDecremented;
    }
    }
    Note: This brilliant piece of code is based on a real homework task (Implement an adder by recursion!) we were assigned at Informatics class at my technical university where I study EE!

  • dvrvm (unregistered) in reply to dvrvm

    Sorry, my code somehow was cut off in the middle.
    The full version is:
    public class SimpleAdderByEleven {
        private int add(int a, int b) throws Exception {
            if ((a<0) || (b<0))
                throw new Exception("Argument out of range");
            if (b>0)
                return add(increment(a),decrement(b));
            else
                return a;
        }
        public int incrementByEleven (int numberToBeIncrementedByEleven) throws Exception
        {
            try {
                return add(eleven(),numberToBeIncrementedByEleven);
            }
            catch(Exception e) {
                throw new Exception("Argument out of range");
            }
        }
        private int generateEleven(int elevenSeed) {
            if (elevenSeed < 11)
                return(generateEleven(++elevenSeed));
            else
                return 11;
        }
        private int eleven(){
            return generateEleven(0);
        }
        private int increment(int numberToBeIncremented) {
            numberToBeIncremented = numberToBeIncremented + (eleven() / eleven());
            return numberToBeIncremented;
        }
        private int decrement(int numberToBeDecremented) {
            numberToBeDecremented = numberToBeDecremented - (eleven() / eleven());
            return numberToBeDecremented;
        }

  • (cs) in reply to dvrvm

    omg, i think i found the real solution:

    public void AddEleven(ref int value)
    {
        int tmp;
        int add = 0;
       
        List<int> list = new List<int>();
       
        while(list.Count <= 11)
        {
            list.Add(1);
        }
       
        add = list.Count;
       
        tmp = value + add;
       
        value = tmp;
    }

  • Anony, the moose (unregistered) in reply to bakkdoor

    <FONT face="Courier New">int increment_by_eleven(int n) {</FONT>

    <FONT face="Courier New">        double pivot = INT_MAX/2.0;
            double x = rand(), old_x = n;</FONT>

    <FONT face="Courier New">        while((x < old_x+10.999) || (x > old_x+11.1)) {
                    if(x < old_x+11) x += pivot;
                    else x -= pivot;</FONT>

    <FONT face="Courier New">                pivot /= 2.0;
            }
            return (int)x;
    }</FONT>

    I think that's as close as anyone can get to the real value, from my tests I'm getting about 99.2% success rate. Who would have thought that binary search would finally pull through.

  • (cs)

    Nathan: Steve, you know how ++ will increment, right?
    Steve: Right ....
    Nathan: Okay, so how do you increment by 11?
    Steve: Oh, that's a bit of a problem. At least the first part is easy, the second part's a problem, but not impossible.
    Nathan: What's the first part?
    Steve: Paste this into notepad and save it. Make sure the first text appears on the first line:

    <FONT face="Courier New" size=2>\1+\v
    |:-1<
    >$@</FONT>

    Nathan: Okay, so what's the second part?
    Steve: You're going to have to write a befunge interpreter that allows you to populate the stack before you execute your script. Push the number you need to increment onto the stack, then push 11, then load your script and run it. Once it's finished, you can simply pop your answer right of the stack.
    Nathan: Gee, thanks Steve, you're so much more helpful than that CS lecturer I had.


     

  • (cs)

    I can't believe nobody has yet come up with the obvious FORTH solution (using prime factors of 42, of course, and a small adjustment)...

    <FONT face="Courier New">: plus11 ( i -- i ) 7 3 2 + + + 1 - ;</FONT>

    Example:

    <FONT face="Courier New">3 plus11 . 14  ok</FONT>

    Tsh.  Amateurs.

    D.

  • klaus (unregistered) in reply to daen

    The obvious solution is:

    double incby(int x, int inc) { int32_t v2; // change to 64 bit if you have the time double v1; v1 = 0; v2 = inc; do{ while( fabs((v2 *= 16807)/2.e10 + 1.72e-9) > 0.1); v1 += v2/2.e10; //printf("%g\n",v1); =) }while( fabs(v1 - inc) > 1.e0);//change to 1.e-9 for extra fun return x + v1; }

    If you really have the time, you can change error and random number generator ... there is no guarantee that this will work for ALL values of inc ^^

  • (cs) in reply to klaus

    i made up a much easier to read version:

    void* addOneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean(void* theValueToWhichWeWillAddOneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean)
    {
        int oneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean = 11;
        int temporaryVariableWhichDoesntHaveAnyPurposeButToFillThatUpcomingForLoop = 0;

        for(int one = 1; i <= oneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean; one++)
        {
            temporaryVariableWhichDoesntHaveAnyPurposeButToFillThatUpcomingForLoop++;
        }   

            (int)theValueToWhichWeWillAddOneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean += oneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean;

        if(thisIsCockyEnough)
        {
            return 0;
        }
    }

  • asdf (unregistered) in reply to bakkdoor

    I think that the proper way to approach a situation like this involves the scripting language Lua. This sample generates 20002 lines of Lua script: int f(int n) { lua_State *L = lua_open(); std::ostringstream x; x << "function f(n)\n"; for(int i = -9999; i < 9999; ++i) x << "\tif(n == " << i << ") then return " << i + 11 << " end\n"; x << "error("PANIC")\nend\n"; luaL_loadstring(L, x.str().c_str()); lua_call(L, 0, 0); lua_getglobal(L, "f"); lua_pushnumber(L, n); lua_call(L, 1, 1); int r = lua_tonumber(L, -1); lua_pop(L, 1); // keep the stack clean lua_close(L); }

  • Adam (unregistered)

        And for advanced programmers:

    Just how do you increment 11 by 11 ?

  • (cs) in reply to Adam

    Anonymous:
        And for advanced programmers:

    Just how do you increment 11 by 11 ?

    <FONT color=#808030><FONT color=#808030><FONT color=#808030>

    <FONT face="Courier New" size=2>((</FONT></FONT><FONT face="Courier New"><FONT size=2><FONT style="BACKGROUND-COLOR: #ffffff" color=#0000ff>1</FONT><FONT color=#000000> </FONT><FONT color=#808030><<</FONT><FONT color=#000000>  </FONT><FONT color=#008c00><FONT color=#0000ff>1</FONT></FONT></FONT></FONT><FONT color=#808030>
    <FONT face="Courier New" size=2>)|</FONT></FONT><FONT face="Courier New"><FONT size=2><FONT color=#0000ff>1</FONT><FONT color=#000000> </FONT><FONT color=#808030>|</FONT><FONT color=#000000> </FONT><FONT color=#808030>( </FONT><FONT color=#0000ff>1</FONT></FONT></FONT><FONT color=#808030><FONT face="Courier New" size=2><<</FONT>
    <FONT face="Courier New" size=2>((</FONT></FONT><FONT face="Courier New"><FONT size=2><FONT color=#0000ff>1</FONT><FONT color=#000000>  </FONT><FONT color=#808030><<</FONT><FONT color=#000000> </FONT><FONT color=#0000ff>1</FONT></FONT></FONT><FONT color=#808030><FONT face="Courier New" size=2>)</FONT>
    <FONT face="Courier New" size=2>|</FONT></FONT><FONT face="Courier New"><FONT size=2><FONT size=1><FONT size=2><FONT color=#000000> </FONT><FONT color=#0000ff>1</FONT><FONT color=#808030>)))<<</FONT><FONT color=#0000ff>1</FONT><FONT color=#800080>;

    </FONT></FONT></FONT></FONT></FONT></FONT><FONT color=#008c00></FONT></FONT><FONT color=#008c00 size=2></FONT>
  • asd007 (unregistered) in reply to Some Idiot

    i just found the obvious solution!

    try{

    x+1=x;

    }

    catch (StupidCoderGenericError)

    {

    }

    try{

    x+1=x;

    }

    catch (StupidCoderGenericError)

    {

    }

    try{

    x+1=x;

    }

    catch (StupidCoderGenericError)

    {

    }

    try{

    x+1=x;

    }

    catch (StupidCoderGenericError)

    {

    }

    try{

    x+1=x;

    }

    catch (StupidCoderGenericError)

    {

    }

    try{

    x+1=x;

    }

    catch (StupidCoderGenericError)

    {

    }

    try{

    x+1=x;

    }

    catch (StupidCoderGenericError)

    {

    }

    try{

    x+1=x;

    }

    catch (StupidCoderGenericError)

    {

    }

    try{

    x+1=x;

    }

    catch (StupidCoderGenericError)

    {

    }

    try{

    x+1=x;

    }

    catch (StupidCoderGenericError)

    {

    }

    try{

    x+1=x;

    }

    catch (StupidCoderGenericError)

    {

    }

     

    try{

    x+1=x;

    }

    catch

    {

    //i'm doomed! can't do it!

    }

     

    i know it needs some brushing up, but the code is promising, right ????

  • asd007 (unregistered) in reply to asd007

    meant x+11=x in the last post

  • (cs)

    Clearly, you should use the correct multi-threaded approach that vastly simplifies the complicated problem at hand.

    You would create one thread that infinitly increments x, and another that stops the first thread after the correct amount of time.

    I believe in Java, It could be written like this:

    //Increments the variable
    public class Incrementer {
          
           private int temp;
          
           //Does the function
           public int doFunction(int x) {
                
                 temp = x;
                
                  final Thread adder = new Thread() {
                             public void run() {
                                      while(true) temp++;
                             }
                       };
                 Thread stopper = new Thread() {
                             public void run() {
                                   try {
                                         int timeForOneIncrement = 1;
                                         sleep(timeForOneIncrement * 11);
                                         adder.stop();
                                   } catch (InterruptedException e) {
                                         /Do nothing, because performing any action that might notify the user something has gone wrong could be dangerous when an Exception has occured./
                                   }
                             }
                    };

                 // Start The Threads!
                 adder.start();
                 stopper.start();
          
                 //Wait for the thread to stop
                 stopper.join();
                 adder.join();

                  //Return the incremented value
                  return temp;
           }
    }

  • (cs) in reply to t722

    Or,

    //Javascript
    eval(String.fromCharCode(120,32,61,32,120,32,43,32,49,49,59));

    For those who prefer not to have any addition or equals signs, nor quotation marks.



    And I would also like to see a brain fuck solution:

    http://en.wikipedia.org/wiki/Brain_Fuck

  • Anon (unregistered) in reply to triso
    triso:
    At least he goes to you for help instead of writing a new compiler which can add correctly or some other WTF.

    Indeed. Haven't we all been in this situation?

    So the coworker has taken the right approach, slipped a little on one statement, did a test (highly commendable!), did notice that the result could not possibly be right despite the simplicity of his code (very observant), and then stared at the problem until the code is now burned into his monitor and his retina.

    The correct response is to tell him how to proceed in this situation: Take a break, walk around for 20 minutes, or tackle an entirely different (non-programming) problem.

    The next cursory glance at the code will then result in a "D'oh" heard through the entire building.

Leave a comment on “If ++ Increments ... (++)”

Log In or post as a guest

Replying to comment #:

« Return to Article