• BigJim in STL (unregistered) in reply to EV

    All I can say to this is....


    <font size="5">BRILLANT!</font>

  • (cs) in reply to Xarium
    Xarium:
    Anonymous:
    for (i = 0; i &lt; 11; i++) {
        i++;
    }

    Nothing cracks me up more than seeing critics try to write "funny" code - only to have it backfire.


    Nothing cracks me up more than seeing a know-all trying to criticise someone's code-quote get broken by this forum wtf-ware than for the wtf-ware to fix it in the reply.

    Although this post will now break it again I imagine.
  • (cs)

    Lots of great solutions, but I do not (WTF, firefox will not allow the single quote.  Specific to this forum and 1.5) see anyone using the do-while construct, which is one of my favorites when you know you have to exeicute the loop at least once.    Saves a comparition, and well all know that premature optimization is good.   Particularly when you want to confuse people like Nathan.

    inc(int i) {
       int j = 0;

      do {
        i++;++j;
       } while(j != 10);

  • (cs)

    Unfortunatelly, most of major programming languages are unable to implement such an operator... Anyway, mathematically, to eleven-increment is the same operation than to increment the result of a ten-increment. And so on. So let's define it (in Foo).

    (&symbol message +++ () (self ++) (self ++))
    (&symbol message ++++ () (self +++) (self ++))
    (&symbol message +++++ () (self ++++) (self ++))
    ...
    (&symbol message ++++++++++++ () (self +++++++++++) (self ++))
    ; so to increment by 11 just use the operator
    ('i ++++++++++++)
  • maht (unregistered) in reply to hank miller
    hank miller:
    Lots of great solutions, but I do not (WTF, firefox will not allow the single quote.  Specific to this forum and 1.5) see anyone using the do-while construct, which is one of my favorites when you know you have to exeicute the loop at least once.    Saves a comparition, and well all know that premature optimization is good.   Particularly when you want to confuse people like Nathan.

    inc(int i) {
       int j = 0;

      do {
        i++;++j;
       } while(j != 10);



    nice try but that only adds on 10


    inc(int i) {

       int j = 11;


      do {

        i++;

       } while(--j);
    }


  • (cs)

    By now, Nathan's hard work is getting notority from the community. Engineers are scrambling to be the first to implement "The Nathan Abacus". Early indications show consensus forming around a pair of operators +|- and -|+

    Each returns an array of numbers:

    x = 20 +|- 11;  would return {21,22,23,24,25,26,27,28,29,30,31}
    x = 20 -|+ 11;  would return {19,18,17,16,15,14,13,12,11,10,9}

    Now Nathan can simply index...   x[nth]

  • (cs)

    Amazing suggestions.

    R.Flowers, Lobachevsky, and Cheem get my votes.

  • Shorty (unregistered) in reply to EV
    Anonymous:
    I always thought it was something like this (excuse me my formatting, I really don't know how to use this forum ;)):

    Private
    Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long,
    ByVal dy As Long, ByVal cButtons As Long,
    ByVal dwExtraInfo As Long)
    Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
    Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
    Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
    Private Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Private Const MOUSEEVENTF_MIDDLEUP = &H40
    Private Const MOUSEEVENTF_RIGHTDOWN = &H8
    Private Const MOUSEEVENTF_RIGHTUP = &H10

    Private Sub inc(iNumToInc11Times As Integer)
    SetCursorPos 32, Screen.Height / 15 - 10
    mouse_event MOUSEEVENTF_ABSOLUTE, 32, Screen.Height / 15 - 10, 1, 1
    mouse_event MOUSEEVENTF_LEFTDOWN, 32, Screen.Height / 15 - 10, 1, 1
    mouse_event MOUSEEVENTF_LEFTUP, 32, Screen.Height / 15 - 10, 1, 1
    SendKeys ("R")
    SendKeys ("calc")
    SendKeys (vbKeyReturn)
    SendKeys (iNumToInc11Times + "+11")
    SendKeys (vbKeyReturn)
    ' TODO: Add some keys to copy it to the clipboard
    inc = Clipboard.GetText()
    End Sub

     

     

    This would not run on my machine [:S] -- i have the panel on the top and czech version of the system *not "run" but "spustit"* so... why not add some localization and panel layout checking? :)

    [8-)]

  • robert (unregistered) in reply to Shorty

    While (I < I + 11)
    {
    I++;
    }

  • (cs) in reply to scooter

    <FONT size=2><FONT color=#ff0000 size=2>

    <FONT face=Arial color=#000000>Assuming that the forum didn't mess up any of my code, this should work.  It's a class I wrote for PHP (5).  It takes into account how precise you want the result, what range to accept possible answers in, allows for comments in the history as well as undo and redo funcationality.  I'll go ahead and submit it to phpclasses.org if anyone wants a plain text copy it takes them a couple days to approve things usually.  </FONT>

    <FONT face="Courier New"><?php
    </FONT><FONT face="Courier New"><FONT color=#800000 size=2>$inc</FONT><FONT size=2><FONT color=#000000> = new floIncrementor();
    </FONT></FONT>
    </FONT><FONT face="Courier New"><FONT size=2><FONT color=#000000><FONT size=2><FONT color=#800000 size=2>$new_value</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$inc</FONT><FONT size=2>->increment(</FONT><FONT color=#ff0000 size=2>20</FONT><FONT size=2>, </FONT><FONT color=#ff0000 size=2>11</FONT><FONT size=2>, </FONT><FONT color=#0000f0 size=2>"Comment: Incrementing 20 by 11 with a precision of .0001, accepting results between 0 and 100."</FONT><FONT size=2>, .</FONT><FONT color=#ff0000 size=2>0001</FONT><FONT size=2>, </FONT><FONT color=#ff0000 size=2>0</FONT><FONT size=2>, </FONT><FONT color=#ff0000 size=2>100</FONT><FONT size=2>);
    </FONT></FONT>
    </FONT></FONT>
    </FONT></FONT><FONT size=2><FONT face="Courier New">class</FONT><FONT face="Courier New"> floIncrementor {
       public </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$last_value_calculated</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>false</FONT></FONT><FONT face="Courier New"><FONT size=2>;
       public </FONT><FONT color=#800000 size=2>$last_increment_value</FONT><FONT size=2> = </FONT><FONT color=#ff0000 size=2>1</FONT></FONT><FONT face="Courier New"><FONT size=2>;
       public </FONT><FONT color=#800000 size=2>$last_precision</FONT><FONT size=2> = .</FONT><FONT color=#ff0000 size=2>0001</FONT></FONT><FONT face="Courier New"><FONT size=2>;
       public </FONT><FONT color=#800000 size=2>$last_max_value</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>false</FONT></FONT><FONT face="Courier New"><FONT size=2>;
       public </FONT><FONT color=#800000 size=2>$last_min_value</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>false</FONT></FONT><FONT face="Courier New"><FONT size=2>;
       public </FONT><FONT color=#800000 size=2>$total_incrementations</FONT><FONT size=2> = </FONT><FONT color=#ff0000 size=2>0</FONT></FONT><FONT face="Courier New"><FONT size=2>;
       public </FONT><FONT color=#800000 size=2>$increment_history_for_undo</FONT></FONT><FONT face="Courier New"><FONT size=2> = array();
       public </FONT><FONT color=#800000 size=2>$increment_history_for_redo</FONT></FONT><FONT face="Courier New"><FONT size=2> = array();
       public </FONT><FONT color=#800000 size=2>$errors</FONT></FONT><FONT face="Courier New"><FONT size=2> = array();
       private </FONT><FONT color=#800000 size=2>$shiftiness</FONT><FONT size=2> = </FONT><FONT color=#ff0000 size=2>1000000000</FONT></FONT><FONT face="Courier New"><FONT size=2>;
       function increment(</FONT><FONT color=#800000 size=2>$initial_value</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>NULL</FONT></FONT><FONT face="Courier New"><FONT size=2>, </FONT><FONT color=#800000 size=2>$increment_by</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>NULL</FONT></FONT><FONT face="Courier New"><FONT size=2>, </FONT><FONT color=#800000 size=2>$comments</FONT><FONT size=2> = </FONT><FONT color=#0000f0 size=2>""</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$precision</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>NULL</FONT></FONT><FONT face="Courier New"><FONT size=2>, </FONT><FONT color=#800000 size=2>$min_result</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>NULL</FONT></FONT><FONT face="Courier New"><FONT size=2>, </FONT><FONT color=#800000 size=2>$max_result</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>NULL</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
          if (</FONT><FONT color=#800000 size=2>$initial_value</FONT><FONT size=2> === </FONT><FONT color=#800000 size=2>NULL</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $initial_value</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->last_value_calculated;
          }
          if (</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$increment_by</FONT><FONT size=2> === </FONT><FONT color=#800000 size=2>NULL</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $increment_by</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->last_increment_value;
    </FONT></FONT><FONT face="Courier New"><FONT size=2>      } else {
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_increment_value = </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$increment_by</FONT><FONT face="Courier New"><FONT size=2>;
          }
          if (</FONT><FONT color=#800000 size=2>$precision</FONT><FONT size=2> === </FONT><FONT color=#800000 size=2>NULL</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $precision</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->last_precision;
          } else {
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_precision = </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$precision</FONT><FONT face="Courier New"><FONT size=2>;
          }
          if (</FONT><FONT color=#800000 size=2>$max_result</FONT><FONT size=2> === </FONT><FONT color=#800000 size=2>NULL</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $max_result</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->last_max_value;
          } else {
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_max_value = </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$max_result</FONT><FONT face="Courier New"><FONT size=2>;
          }
          if (</FONT><FONT color=#800000 size=2>$min_result</FONT><FONT size=2> === </FONT><FONT color=#800000 size=2>NULL</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $min_result</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->last_min_value;
          } else {
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_min_value = </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$min_result</FONT><FONT face="Courier New"><FONT size=2>;
          }
    </FONT><FONT color=#800000 size=2>      $history_key</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->create_increment_history_record(</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$initial_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$increment_by</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$precision</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$comments</FONT></FONT><FONT face="Courier New"><FONT size=2>);
    </FONT><FONT color=#800000 size=2>      $this</FONT><FONT size=2>->recursive_incrementator(</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$history_key</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$initial_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$increment_by</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$precision</FONT><FONT size=2> / </FONT><FONT color=#800000 size=2>$increment_by</FONT></FONT><FONT face="Courier New"><FONT size=2>);
          if ((</FONT><FONT color=#800000 size=2>$return_value</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->retrieve_history_result()) !== </FONT></FONT><FONT color=#800000 size=2><FONT face="Courier New">false</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
             if (</FONT><FONT color=#800000 size=2>$max_result</FONT><FONT size=2> !== </FONT><FONT color=#800000 size=2>false</FONT></FONT><FONT face="Courier New"><FONT size=2> && </FONT><FONT color=#800000 size=2>$return_value</FONT><FONT size=2> > </FONT><FONT color=#800000 size=2>$max_result</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>            $this</FONT><FONT size=2>->errors[] = </FONT></FONT><FONT face="Courier New"><FONT color=#0000f0 size=2>"Resulting value of "</FONT><FONT size=2>.</FONT><FONT color=#800000 size=2>$return_value</FONT><FONT size=2>.</FONT><FONT color=#0000f0 size=2>" excedes maximum of "</FONT><FONT size=2>.</FONT><FONT color=#800000 size=2>$max_result</FONT><FONT size=2>.</FONT><FONT color=#0000f0 size=2>". "</FONT></FONT><FONT face="Courier New"><FONT size=2>;
                return </FONT><FONT color=#800000 size=2>false</FONT></FONT><FONT face="Courier New"><FONT size=2>;
             }
             if (</FONT><FONT color=#800000 size=2>$min_result</FONT><FONT size=2> !== </FONT><FONT color=#800000 size=2>false</FONT></FONT><FONT face="Courier New"><FONT size=2> && </FONT><FONT color=#800000 size=2>$return_value</FONT><FONT size=2> < </FONT><FONT color=#800000 size=2>$min_result</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>            $this</FONT><FONT size=2>->errors[] = </FONT></FONT><FONT face="Courier New"><FONT color=#0000f0 size=2>"Resulting value of "</FONT><FONT size=2>.</FONT><FONT color=#800000 size=2>$return_value</FONT><FONT size=2>.</FONT><FONT color=#0000f0 size=2>" is lower than minimum "</FONT><FONT size=2>.</FONT><FONT color=#800000 size=2>$min_result</FONT><FONT size=2>.</FONT><FONT color=#0000f0 size=2>". "</FONT></FONT><FONT face="Courier New"><FONT size=2>;
                return </FONT><FONT color=#800000 size=2>false</FONT></FONT><FONT face="Courier New"><FONT size=2>;
             }
          }
    </FONT><FONT color=#800000 size=2>      $this</FONT><FONT size=2>->last_value_calculated = </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$return_value</FONT><FONT face="Courier New"><FONT size=2>;
          return </FONT><FONT color=#800000 size=2>$return_value</FONT></FONT><FONT face="Courier New"><FONT size=2>;
       }
       function retrieve_history_result(</FONT><FONT color=#800000 size=2>$back_how_far</FONT><FONT size=2> = </FONT><FONT color=#ff0000 size=2>1</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>      $tmp_history</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->increment_history_for_undo;
          while((</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$back_how_far</FONT><FONT size=2>--) > </FONT><FONT color=#ff0000 size=2>0</FONT></FONT><FONT face="Courier New"><FONT size=2>){
    </FONT><FONT color=#800000 size=2>         $tmp_record</FONT><FONT size=2> = array_pop(</FONT><FONT color=#800000 size=2>$tmp_history</FONT></FONT><FONT face="Courier New" size=2>);
          } </FONT><FONT face="Courier New"><FONT color=#c0c000 size=2>// while
    </FONT><FONT size=2>      if (is_array(</FONT><FONT color=#800000 size=2>$tmp_record</FONT><FONT size=2>[</FONT><FONT color=#0000f0 size=2>"recursion"</FONT><FONT size=2>]) && </FONT><FONT color=#800000 size=2>$tmp_last_incrementation</FONT><FONT size=2> = array_pop(</FONT><FONT color=#800000 size=2>$tmp_record</FONT><FONT size=2>[</FONT><FONT color=#0000f0 size=2>"recursion"</FONT></FONT><FONT face="Courier New"><FONT size=2>])) {
             return </FONT><FONT color=#800000 size=2>$tmp_last_incrementation</FONT><FONT size=2>[</FONT><FONT color=#0000f0 size=2>"return_value"</FONT></FONT><FONT face="Courier New"><FONT size=2>];
          } else {
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->errors[] = </FONT></FONT><FONT face="Courier New" color=#0000f0 size=2>"Unable to determine last incrementation, clearing UNDO history. "</FONT><FONT face="Courier New"><FONT size=2>;
             return </FONT><FONT color=#800000 size=2>false</FONT></FONT><FONT face="Courier New"><FONT size=2>;
          }
       }
       public function undo() {
    </FONT><FONT color=#800000 size=2>      $tmp_undo</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->increment_history_for_undo;
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>      $tmp_redo</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->increment_history_for_redo;
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>      $tmp_moving_record</FONT><FONT size=2> = array_pop(</FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->increment_history_for_undo);
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>      $tmp_undo_2</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->increment_history_for_undo;
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>      $tmp_last_record</FONT><FONT size=2> = array_pop(</FONT><FONT color=#800000 size=2>$tmp_undo_2</FONT></FONT><FONT face="Courier New"><FONT size=2>);
          if (</FONT><FONT color=#800000 size=2>$tmp_moving_record</FONT><FONT size=2> && </FONT><FONT color=#800000 size=2>$tmp_last_record</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->increment_history_for_redo[] = </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$tmp_moving_record</FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_value_calculated = </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$this</FONT><FONT size=2>->retrieve_history_result();
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_increment_value = </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$tmp_last_record</FONT><FONT size=2>[</FONT><FONT color=#0000f0 size=2>"inc_value"</FONT></FONT><FONT face="Courier New"><FONT size=2>];
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_precision = </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$tmp_last_record</FONT><FONT size=2>[</FONT><FONT color=#0000f0 size=2>"precision"</FONT></FONT><FONT face="Courier New"><FONT size=2>];
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_max_value = </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$tmp_last_record</FONT><FONT size=2>[</FONT><FONT color=#0000f0 size=2>"min_value"</FONT></FONT><FONT face="Courier New"><FONT size=2>];
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_min_value = </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$tmp_last_record</FONT><FONT size=2>[</FONT><FONT color=#0000f0 size=2>"max_value"</FONT></FONT><FONT face="Courier New"><FONT size=2>];
             return </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->retrieve_history_result();
          } else {
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->increment_history_for_undo = </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$tmp_undo</FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->increment_history_for_redo = </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$tmp_redo</FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->erros[] = </FONT></FONT><FONT face="Courier New" color=#0000f0 size=2>"Undo failed, no current or previous record. "</FONT><FONT face="Courier New"><FONT size=2>;
          }
          return </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->last_value_calculated;
       }
       public function redo() {
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>      $tmp_undo</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->increment_history_for_undo;
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>      $tmp_redo</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->increment_history_for_redo;
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>      $tmp_moving_record</FONT><FONT size=2> = array_pop(</FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->increment_history_for_redo);
          if (</FONT></FONT><FONT face="Courier New" color=#800000 size=2>$tmp_moving_record</FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->increment_history_for_undo[] = </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$tmp_moving_record</FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_value_calculated = </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$this</FONT><FONT size=2>->retrieve_history_result();
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_increment_value = </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$tmp_last_record</FONT><FONT size=2>[</FONT><FONT color=#0000f0 size=2>"inc_value"</FONT></FONT><FONT face="Courier New"><FONT size=2>];
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_precision = </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$tmp_last_record</FONT><FONT size=2>[</FONT><FONT color=#0000f0 size=2>"precision"</FONT></FONT><FONT face="Courier New"><FONT size=2>];
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_max_value = </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$tmp_last_record</FONT><FONT size=2>[</FONT><FONT color=#0000f0 size=2>"min_value"</FONT></FONT><FONT face="Courier New"><FONT size=2>];
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->last_min_value = </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$tmp_last_record</FONT><FONT size=2>[</FONT><FONT color=#0000f0 size=2>"max_value"</FONT></FONT><FONT face="Courier New"><FONT size=2>];
             return </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->retrieve_history_result();
          } else {
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->increment_history_for_undo = </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$tmp_undo</FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->increment_history_for_redo = </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$tmp_redo</FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->erros[] = </FONT></FONT><FONT face="Courier New" color=#0000f0 size=2>"Redo failed, no current or previous record. "</FONT><FONT face="Courier New"><FONT size=2>;
          }
          return </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->last_value_calculated;
       }
       private function create_increment_history_record(</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$start_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$inc_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$precision</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$comments</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
          if (</FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->last_value_calculated != </FONT></FONT><FONT face="Courier New" color=#800000 size=2>$start_value</FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->increment_history_for_undo = array();
          }
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>      $this</FONT><FONT size=2>->increment_history_for_redo = array();
    </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>      $this</FONT><FONT size=2>->increment_history_for_undo[] = array(
    </FONT></FONT><FONT face="Courier New"><FONT color=#0000f0 size=2>         "start_value"</FONT><FONT size=2> => </FONT><FONT color=#800000 size=2>$start_value</FONT></FONT><FONT face="Courier New"><FONT size=2>,
    </FONT><FONT color=#0000f0 size=2>         "inc_value"</FONT><FONT size=2> => </FONT><FONT color=#800000 size=2>$inc_value</FONT></FONT><FONT face="Courier New"><FONT size=2>,
    </FONT><FONT color=#0000f0 size=2>         "precision"</FONT><FONT size=2> => </FONT><FONT color=#800000 size=2>$precision</FONT></FONT><FONT face="Courier New"><FONT size=2>,
    </FONT><FONT color=#0000f0 size=2>         "comments"</FONT><FONT size=2> => </FONT><FONT color=#800000 size=2>$comments</FONT></FONT><FONT face="Courier New"><FONT size=2>,
    </FONT><FONT color=#0000f0 size=2>         "min_value"</FONT><FONT size=2> => </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->last_min_value,
    </FONT></FONT><FONT face="Courier New"><FONT color=#0000f0 size=2>         "max_value"</FONT><FONT size=2> => </FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->last_max_value,
    </FONT></FONT><FONT face="Courier New" color=#0000f0 size=2>         "recursion"</FONT><FONT face="Courier New"><FONT size=2> => array()
          );
          return array_pop(array_keys(</FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->increment_history_for_undo));
       }
       private function increment_increment_history_record(</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$history_key</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$starting_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$tollerance_adjusted</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$return_value</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>      $this</FONT><FONT size=2>->increment_history_for_undo[</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$history_key</FONT><FONT size=2>][</FONT><FONT color=#0000f0 size=2>"recursion"</FONT></FONT><FONT face="Courier New"><FONT size=2>][] = array(
    </FONT><FONT color=#0000f0 size=2>         "starting_value"</FONT><FONT size=2> => </FONT><FONT color=#800000 size=2>$starting_value</FONT></FONT><FONT face="Courier New"><FONT size=2>,
    </FONT><FONT color=#0000f0 size=2>         "target_increment"</FONT><FONT size=2> => </FONT><FONT color=#800000 size=2>$target_increment</FONT></FONT><FONT face="Courier New"><FONT size=2>,
    </FONT><FONT color=#0000f0 size=2>         "tollerance_adjusted"</FONT><FONT size=2> => </FONT><FONT color=#800000 size=2>$tollerance_adjusted</FONT></FONT><FONT face="Courier New"><FONT size=2>,
    </FONT><FONT color=#0000f0 size=2>         "return_value"</FONT><FONT size=2> => </FONT><FONT color=#800000 size=2>$return_value</FONT></FONT><FONT face="Courier New"><FONT size=2>,
          );
       }
       private function recursive_incrementator(</FONT><FONT color=#800000 size=2>$history_key</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$current_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$tollerance</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>      $tolerance_shift_percentage</FONT><FONT size=2> = rand(</FONT><FONT color=#ff0000 size=2>0</FONT><FONT size=2>-</FONT><FONT color=#800000 size=2>$this</FONT><FONT size=2>->shiftiness, </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$this</FONT><FONT size=2>->shiftiness) / </FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$this</FONT><FONT size=2>->shiftiness;
          if (</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2> > </FONT><FONT color=#ff0000 size=2>1</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $tollerance_adjustment</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$tollerance</FONT><FONT size=2> * </FONT><FONT color=#800000 size=2>$tolerance_shift_percentage</FONT></FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $return_value</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$current_value</FONT><FONT size=2> + </FONT><FONT color=#ff0000 size=2>1</FONT><FONT size=2> + </FONT><FONT color=#800000 size=2>$tollerance_adjustment</FONT></FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->increment_increment_history_record(</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$history_key</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$current_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$tollerance_adjustment</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$return_value</FONT></FONT><FONT face="Courier New"><FONT size=2>);
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->recursive_incrementator(</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$history_key</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$return_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2> - </FONT><FONT color=#ff0000 size=2>1</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$tollerance</FONT></FONT><FONT face="Courier New"><FONT size=2>);
          } elseif (</FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2> < -</FONT><FONT color=#ff0000 size=2>1</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $tollerance_adjustment</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$tollerance</FONT><FONT size=2> * </FONT><FONT color=#800000 size=2>$tolerance_shift_percentage</FONT></FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $return_value</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$current_value</FONT><FONT size=2> - </FONT><FONT color=#ff0000 size=2>1</FONT><FONT size=2> - </FONT><FONT color=#800000 size=2>$tollerance_adjustment</FONT></FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->increment_increment_history_record(</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$history_key</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$current_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$tollerance_adjustment</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$return_value</FONT></FONT><FONT face="Courier New"><FONT size=2>);
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->recursive_incrementator(</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$history_key</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$return_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2> + </FONT><FONT color=#ff0000 size=2>1</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$tollerance</FONT></FONT><FONT face="Courier New"><FONT size=2>);
          } elseif (</FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2> > </FONT><FONT color=#ff0000 size=2>0</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $tollerance_adjustment</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$tollerance</FONT><FONT size=2> * </FONT><FONT color=#800000 size=2>$tolerance_shift_percentage</FONT><FONT size=2> / </FONT><FONT color=#800000 size=2>$target_increment</FONT></FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $return_value</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$current_value</FONT><FONT size=2> + </FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2> + </FONT><FONT color=#800000 size=2>$tollerance_adjustment</FONT></FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->increment_increment_history_record(</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$history_key</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$current_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$tollerance_adjustment</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$return_value</FONT></FONT><FONT face="Courier New"><FONT size=2>);
          } elseif (</FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2> < </FONT><FONT color=#ff0000 size=2>0</FONT></FONT><FONT face="Courier New"><FONT size=2>) {
    </FONT><FONT color=#800000 size=2>         $tollerance_adjustment</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$tollerance</FONT><FONT size=2> * </FONT><FONT color=#800000 size=2>$tolerance_shift_percentage</FONT><FONT size=2> / </FONT><FONT color=#800000 size=2>$target_increment</FONT></FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $return_value</FONT><FONT size=2> = </FONT><FONT color=#800000 size=2>$current_value</FONT><FONT size=2> - </FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2> - </FONT><FONT color=#800000 size=2>$tollerance_adjustment</FONT></FONT><FONT face="Courier New"><FONT size=2>;
    </FONT><FONT color=#800000 size=2>         $this</FONT><FONT size=2>->increment_increment_history_record(</FONT></FONT><FONT face="Courier New"><FONT color=#800000 size=2>$history_key</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$current_value</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$target_increment</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$tollerance_adjustment</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>$return_value</FONT></FONT><FONT face="Courier New"><FONT size=2>);
          }
       }
    }
    </FONT><FONT color=#ff0000 size=2>?></FONT></FONT></FONT>

  • (cs) in reply to flobi

    Hmm, I think I should have used the word accuracy instead of precision.  Oh well, make that change mentally if you use it, k? 

  • (cs) in reply to flobi

    I put an example of it's use here:

    http://www.flobi.com/test/floIncrementor/

  • Anonymous (unregistered) in reply to hank miller

    do...while is NOT just a "premature optimization". There are many times when it is simply the only appropriate control structure to use. For example, consider reading the time deltas in a MIDI track. They are variable length, the low 7 bits in each byte are the data and the highest bit is set on all but the last byte. You could read them with code like this:

    int time = 0;

    int byte;
    do {
        byte = *p++;
        time <<= 7;
        time |= byte & 0x7F;
    } while (byte & 0x80);

    If you were to use a regular while instead, you would have to initialize byte with some value, completely unrelated to the actual data you're reading, just to make the loop work.

  • uncool (unregistered) in reply to robert

    <FONT style="BACKGROUND-COLOR: #9acd32">Nathan: Steve, you know how ++ will increment, right?</FONT>

    if (x + 1 == x++)

    <FONT style="BACKGROUND-COLOR: #9acd32">Steve: Right ....</FONT>
    {
    while (y +x < x+11)
    {
    y++;
    }

    <FONT style="BACKGROUND-COLOR: #9acd32">Nathan: Okay, so how do you increment by 11?</FONT>
    x= x+y;
    }

     

    I'm sure it's broke in lots of places... been in a lisp world too long, but i still thought it might be fun

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

    Preferrably by introducing floating point errors.


    x += 10.9?
  • (cs)

    "Oh, well, 11 is such a problem, you cant even make a function for it, you have to do it in assembly."

    .def    ___main;        .scl    2;      .type   32;     .endef
    .text
    .globl _main
    .def _main; .scl 2; .type 32; .endef

    _main:
     pushl  %ebp
     movl  %esp, %ebp
     subl   $8, %esp
     andl   $-16, %esp
     movl  $0, %eax
     addl   $15, %eax
     addl   $15, %eax
     shrl   $4, %eax
     sall   $4, %eax
     movl    %eax, -4(%ebp)
     movl    -4(%ebp), %eax
     call    __alloca
     call    ___main
    L2:
     cmpl    $11, 8(%ebp)
     je    L3
     incl    8(%ebp)
     jmp    L2
    L3:
     movl    $0, (%esp)
     call    _exit
     .def    _exit; .scl 3; .type 32; .endef

    <crossing fingers...>

  • Dave (unregistered)

    #pragma pack(1) struct foo { char bumper[11]; }; ++(struct foo*)x;

  • Dave (unregistered) in reply to Dave

    Oops:

    #pragma pack(1) struct foo { char bumper[11]; }; ++(struct foo*)&x;

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

    Preferrably by introducing floating point errors.


    x += 10.9?


    You must be crazy.  10.9 insn't close enough.  Should be:

    x += 10.999999999999999999999999999999999999999999999999999999999999999999999999999999999 ...snip (for clarity)... 999999999999999999999999999999999999999999999999999999999999999999999999999999999

    sheeesh... and you call yourselves programmers!
  • (cs) in reply to TankerJoe

    Oh, come off it.

    [tongue-in-cheek] This is quite clearly the only rational way to add 11 to a number. In fact, this OOP class can increment by any value from 1 to 20, and if you need more than that you can chain your calls! And because it's OOP, it's obvious that this is the way forward...

    #!/usr/bin/perl -w
    use strict;
    
    print "Now we will increment the number 5 by 11.\n";
    my $i = new WTF::Incrementer;
    $i->incrementNumber(11);
    my $number = $i->getNumber();
    print "5 and 11 make $number!\n\n";
    $i = undef;
    
    print "Now you can try it yourself! Enter the number to increment by 11: ";
    $number = <STDIN>;
    chomp($number);
    
    $i = new WTF::Incrementer;
    $i->putNumber($number);
    $i->incrementNumber(5)->incrementNumber(6);
    my $newnumber = $i->getNumber();
    $i = undef;
    
    print "$number and 11 make $newnumber!\n";
    exit(0);
    
    # ----------------------------------
    
    package WTF::Incrementer;
    use strict;
    
    sub new {
      my ($class) = @_;
      my $obj = {
                  number => new WTF::Incrementor::Number (5),        # default number - more confusing this way
                  mappingtable => {   # for flexibility in case any changes are needed
                    1 => new WTF::Incrementor::Number (1),
                    2 => new WTF::Incrementor::Number (2),
                    3 => new WTF::Incrementor::Number (3),
                    4 => new WTF::Incrementor::Number (4),
                    5 => new WTF::Incrementor::Number (5),
                    6 => new WTF::Incrementor::Number (6),
                    7 => new WTF::Incrementor::Number (7),
                    8 => new WTF::Incrementor::Number (8),
                    9 => new WTF::Incrementor::Number (9),
                    10 => new WTF::Incrementor::Number (10),
                    11 => new WTF::Incrementor::Number (11),
                    12 => new WTF::Incrementor::Number (12),
                    13 => new WTF::Incrementor::Number (13),
                    14 => new WTF::Incrementor::Number (14),
                    15 => new WTF::Incrementor::Number (15),
                    16 => new WTF::Incrementor::Number (16),
                    17 => new WTF::Incrementor::Number (17),
                    18 => new WTF::Incrementor::Number (18),
                    19 => new WTF::Incrementor::Number (19),
                    20 => new WTF::Incrementor::Number (20),
                  },
                };
      bless $obj, $class;
      return $obj;
    }
    
    sub putNumber {
      my ($self, $number) = @_;
      $self->{"number"} = $self->{"mappingtable"}->{"$number"};
      return 84;   # any non-zero value is considered true by Perl, so why not 84?
    }
    
    sub incrementNumber {
      my ($self, $number) = @_;
      my $orignumber;
      $orignumber = $self->{"number"}->getNumber();
      $orignumber += $self->{"mappingtable"}->{"$number"}->getNumber();   # notice how flexible this is!
      $self->{"number"} = WTF::Incrementor::Number->new($orignumber);
      return $self;   # notice that we don't return the result here. That would be far too useful.
                      # instead, we return ourselves so we can do lengthy chain operations, because
                      # we like chaining things.
    }
    
    sub getNumber {
      my ($self) = @_;
      my $number = $self->{"number"}->getNumber();
      return $number;   # sadly, we have to return the number here. There's no choice really.
    }
    
    # ----------------------------------
    
    package WTF::Incrementor::Number;
    
    sub new {
      my ($class, $number) = @_;
      my $obj = {
                  number => $number,
                };
      bless $obj, $class;
      return $obj;
    }
    
    sub getNumber {
      my ($self) = @_;
      return $self->{"number"};
    }
    

    And if this foum decides to bork up that code, which it probably will given that I've never tried to post code here before and lots of other people have problems, I've posted a copy at http://theblob.org/11.pl too. [/tongue-in-cheek]

    See how many WTFs you can spot. I did my best to include as many as I could, including a subtle one that might not be immediately obvious. ;)

  • (cs) in reply to Ciaran

    Just as I thought. sigh Okay, make your way to http://theblob.org/11.pl and view it there. See how many WTFs you can spot. :D

  • (cs) in reply to Gene Wirchenko
    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.

  • werewrwe (unregistered) 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.



    Even if he's never seen +=. He's probably i = i + 11... Which is the same thing...
  • (cs) in reply to KraGiE

    KraGiE:
    Gene Wirchenko:

    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.

    /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.

    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.

     

  • (cs) in reply to Ciaran
    Ciaran:
    Just as I thought. *sigh* Okay, make your way to http://theblob.org/11.pl and view it there. See how many WTFs you can spot. :D


    There's the first WTF

  • Ismaelj (unregistered)

    A JavaScript solution would be something like this:

      var a = "1";
      var b = "1";
    

    var x = a + b;

    Hope this helps Steve... [8-|]

  • (cs) in reply to Mike
    Anonymous:

    I get this sorta stuff from my coworker all the time!

    <font color="#0000ff">coworker</font>: i have a question...
    <font color="#ff0000">me</font>: alright
    <font color="#0000ff">coworker</font>: i have two subtotal amounts... 31.90 and 49.90... when i add them up in my code, i get the total amount of 99.80... which is way wrong
    <font color="#0000ff">coworker</font>: my code is: this_subtotalprice = subtotal + subtotal
    <font color="#0000ff">coworker</font>: any ideas why it's giving me an extra 19?

    *sound of head banging on desk reverberate across world*


    <font size="5">A</font>t least he goes to you for help instead of writing a new compiler which can add correctly or some other WTF.

  • rob_squared (unregistered) in reply to robert

    while(i!=i+11, i++)

  • (cs) in reply to rob_squared

    Anonymous:
    while(i!=i+11, i++)

    That'll keep Nathan busy...

  • c2thunes (unregistered)

    i = 10*((i/10)+1) + (i%10+1)

  • Anonymous (unregistered) in reply to Maz
    Maz:

    <font color="#000000">Wouldn't it have been obvious...</font>

    variable(++)(++)(++)(++)(++)(++)(++)(++)(++)(++)(++)

    or to mix it up a little

    (++)(++)(++)(++)(++)variable(++)(++)(++)(++)(++)(++)



    I don't know what language you're in, but if it's C, C++, C#, or Java, neither of these will work. You can't chain postfix ++ operators.

    Reason is (expression)++ needs (expression) to be an l-value, and i++ isn't.

    C or C++ will allow you to do ++++++...++i, but you can't do postfix.

    Also, you can't group the parens around the ++; you need to either omit them or write ++(++(i)).

    (Truth be told I didn't try Java.)
  • EvanED (unregistered) in reply to GuruBuckaroo
    Anonymous:
    Anonymous:
    A Modern C++ version:

    // Abstract class for Incrementor interface
    template<class t="">
    class IncrementorBase
    {
    public:
      IncrementorBase() {}
      virtual ~IncrementorBase() {}
      virtual  T operator+(const T& rhs) const = 0;
    };
    // General Purpose Integer Incrementor
    // Assumes T has an over-ride for operator+(int)
    template<class t="" int="" amount="">
    class Incrementor : public IncrementorBase<t>
    {
    public:
     Incrementor()  {}
     virtual ~Incrementor() {}
     virtual  T operator+(const T& rhs) const { return T(rhs + Amount); } // it's safe to do this becuase addition is commutative
    };
    typedef Incrementor<int, 11=""> IntElevenIncrementor;

    int IncrementByEleven(int i)
    {
     IntElevenIncrementor i11;
     return incr+i;
    }


    And this is exactly why I refuse to learn C++.
    </int,></t></class></class>


    Why, because you can write sucky code in it?

    For someone who hangs around this site, you should know you can do WTF-worthy code in ANY language.
  • asifyoucare (unregistered) in reply to TankerJoe

    Just use " x += 11.0;" and use a Pentium.  The Pentium should look after the 'almost'.

  • Anonymous (unregistered) in reply to BigJim in STL
    Anonymous:
    All I can say to this is....


    <font size="5">BRILLANT!</font>

    Same
  • (cs) in reply to Otto
    Otto:

    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.


    Very easy: to anyone who knows matematics but is not familiar with C-like languages, that statement makes little sense. = is an equality assertion, and x=x+11 is true only if x is infinity or if you're working in a trivial or a mod 11 algebra.
  • (cs)

    I'll bet this guy learned to program in brainf**k.

  • ralph l mayo (unregistered) in reply to dhromed

    What's up with all these people hard coding the value of eleven?  Is it really that hard to derive it from the time of the Sunrise on Thanksgiving '94 in Lisbon like they do at the Numeric Standards Insititue?  That's what date_sunrise() is there for, people.  And let's see some error handling.

    <?php<br>function incrementByEleven($num)
    {
    for ($ii = strlen($s = (string) date_sunrise(strtotime('oct 31 1994 next thursday +2 weeks'), SUNFUNCS_RET_TIMESTAMP, 38.4, -9, 90, 1)), --$ii; $ii >= 0; --$ii)
    {
    $op = ($s[$ii] == 0) ? '+= $s +' : ($s[$ii] % 3 == 0) ? '-=' : ($s *= $s) ? '*=' : 'horses';
    eval('$s ' . $op . ' $s[$ii];');
    $s /= ($s < 10) ? -atan(--$s) : $s*$s/2;
    }
    throw new Exception('', $num + str_repeat(substr(($s = (string)$s), $s[8] - ($s[4] + $s[1]), $s[1]), $s[$s[13]]));
    }

    try
    {
    incrementByEleven(1);
    }
    catch (Exception $e)
    {
    echo $e->getCode();
    }
    ?>

  • ralph l mayo (unregistered) in reply to ralph l mayo

    The end of that loops is supposed to be

    $s /= ($s < 10) ? -atan(--$s) : $s*$s/2; }

    of course.

  • Berty (unregistered) in reply to dhromed
    <FONT size=2>

    i += pow(2.0,3.459)

    </FONT>
  • Eric Jablow (unregistered) in reply to Berty

    You do it like this:

    int rest = 11;

    do { int dummy = x & rest; x |= rest; rest = dummy << 1; } while (rest);

  • (cs) in reply to Eric Jablow
    Anonymous:
    You do it like this:

    int rest = 11;

    do { int dummy = x & rest; x |= rest; rest = dummy << 1; } while (rest);



    What kind of operator is |=?

  • (cs) in reply to dhromed
    dhromed:
    Anonymous:
    You do it like this:

    int rest = 11;

    do { int dummy = x & rest; x |= rest; rest = dummy << 1; } while (rest);



    What kind of operator is |=?


    Combined bitwise OR and assignment.

  • (cs) in reply to brazzy

    brazzy:
    dhromed:
    Anonymous:
    You do it like this: int rest = 11; do { int dummy = x & rest; x |= rest; rest = dummy << 1; } while (rest);


    What kind of operator is |=?


    Combined bitwise OR and assignment.

    This looks remarkably like the receipe for soup no. 11 ( orign withheld ) -- At least the logic is similar. You start with 11 holiday leftovers, and you assign them ( or not ) to the soup. Either way, you've made a choice on each leftover, and in the end.. you always have soup no. 11 ( chosen from 11 leftovers ).

  • EV (unregistered) in reply to ralph l mayo
    Anonymous:
    What's up with all these people hard coding the value of eleven?  Is it really that hard to derive it from the time of the Sunrise on Thanksgiving '94 in Lisbon like they do at the Numeric Standards Insititue?  That's what date_sunrise() is there for, people.  And let's see some error handling.

    function incrementByEleven($num)
    {
    for ($ii = strlen($s = (string) date_sunrise(strtotime('oct 31 1994 next thursday +2 weeks'), SUNFUNCS_RET_TIMESTAMP, 38.4, -9, 90, 1)), --$ii; $ii >= 0; --$ii)
    {
    $op = ($s[$ii] == 0) ? '+= $s +' : ($s[$ii] % 3 == 0) ? '-=' : ($s *= $s) ? '*=' : 'horses';
    eval('$s ' . $op . ' $s[$ii];');
    $s /= ($s < 10) ? -atan(--$s) : $s*$s/2;
    }
    throw new Exception('', $num + str_repeat(substr(($s = (string)$s), $s[8] - ($s[4] + $s[1]), $s[1]), $s[$s[13]]));
    }

    try
    {
    incrementByEleven(1);
    }
    catch (Exception $e)
    {
    echo $e->getCode();
    }
    ?>




    That one sucks with backward compatibility. Here, this one's better:
    function incrementByEleven($num)
    {
    if(function_exists('date_sunrise'))
    {
    $s = (string)
    date_sunrise(strtotime('oct 31 1994 next thursday +2 weeks'), SUNFUNCS_RET_TIMESTAMP, 38.4, -9, 90, 1);
    } else {
    $t = split("\.", phpversion());
    $s = substr("AAAA[.....]AAAAA", 0, ($t[0] << 2) - $t[1] - $t[2]);
    }

    for ($ii = strlen($s), --$ii; $ii >= 0; --$ii)
    {
    $op = ($s[$ii] == 0) ? '+= $s +' : ($s[$ii] % 3 == 0) ? '-=' : ($s *= $s) ? '*=' : 'horses';
    eval('$s ' . $op . ' $s[$ii];');
    $s /= ($s < 10) ? -atan(--$s) : $s*$s/2;
    }
    return $num + str_repeat(substr(($s = (string)$s), $s[8] - ($s[4] + $s[1]), $s[1]), $s[$s[13]]);
    }
  • EV (unregistered) in reply to EV
    Anonymous:
    Anonymous:
    What's up with all these people hard coding the value of eleven?  Is it really that hard to derive it from the time of the Sunrise on Thanksgiving '94 in Lisbon like they do at the Numeric Standards Insititue?  That's what date_sunrise() is there for, people.  And let's see some error handling.

    function incrementByEleven($num)
    {
    for ($ii = strlen($s = (string) date_sunrise(strtotime('oct 31 1994 next thursday +2 weeks'), SUNFUNCS_RET_TIMESTAMP, 38.4, -9, 90, 1)), --$ii; $ii >= 0; --$ii)
    {
    $op = ($s[$ii] == 0) ? '+= $s +' : ($s[$ii] % 3 == 0) ? '-=' : ($s *= $s) ? '*=' : 'horses';
    eval('$s ' . $op . ' $s[$ii];');
    $s /= ($s < 10) ? -atan(--$s) : $s*$s/2;
    }
    throw new Exception('', $num + str_repeat(substr(($s = (string)$s), $s[8] - ($s[4] + $s[1]), $s[1]), $s[$s[13]]));
    }

    try
    {
    incrementByEleven(1);
    }
    catch (Exception $e)
    {
    echo $e->getCode();
    }
    ?>




    That one sucks with backward compatibility. Here, this one's better:
    function incrementByEleven($num)
    {
    if(function_exists('date_sunrise'))
    {
    $s = (string)
    date_sunrise(strtotime('oct 31 1994 next thursday +2 weeks'), SUNFUNCS_RET_TIMESTAMP, 38.4, -9, 90, 1);
    } else {
    $t = split("\.", phpversion());
    $s = substr("AAAA[.....]AAAAA", 0, ($t[0] &lt;&lt; 2) - $t[1] - $t[2]);
    }

    for ($ii = strlen($s), --$ii; $ii >= 0; --$ii)
    {
    $op = ($s[$ii] == 0) ? '+= $s +' : ($s[$ii] % 3 == 0) ? '-=' : ($s *= $s) ? '*=' : 'horses';
    eval('$s ' . $op . ' $s[$ii];');
    $s /= ($s < 10) ? -atan(--$s) : $s*$s/2;
    }
    return $num + str_repeat(substr(($s = (string)$s), $s[8] - ($s[4] + $s[1]), $s[1]), $s[$s[13]]);
    }
  • (cs) in reply to Kiss me, I'm Polish
    Anonymous:

    Why not use tools that you have for free.


    function AddElevenToX( int x ) {
      System.Clipboard.put( x );
      System.run("calc.exe");
      System.keyboard.press("V", "Ctrl");
      System.keyboard.press("+", none);
      System.keyboard.press("1", none);
      for ( i = 1; i <= 11; i++ ) {
        System.keyboard.press( "=", none);
      }
      System.keyboard.press("C", "Ctrl");
      System.Clipboard.get( x );
     return x;
    }

     

    This would have to be the best solution i have seen in a long time.

    does it close the calculator though?

  • Eric Jablow (unregistered) in reply to Eric Jablow

    I really am dumb today. That should have been x^= rest, not x |= rest. Exclusive or, not simple or.

  • GreenSprite (unregistered) in reply to Kiss me, I'm Polish
    Anonymous:

    Why not use tools that you have for free.


    function AddElevenToX( int x ) {
      System.Clipboard.put( x );
      System.run("calc.exe");
      System.keyboard.press("V", "Ctrl");
      System.keyboard.press("+", none);
      System.keyboard.press("1", none);
      for ( i = 1; i <= 11; i++ ) {
        System.keyboard.press( "=", none);
      }
      System.keyboard.press("C", "Ctrl");
      System.Clipboard.get( x );
     return x;
    }



    Hmm. Is that an actual framework, or some psudo-code? Looks like .NET, but more intuitive? Actually looks like Windows Script Host meets .NET.
  • Jens (unregistered) in reply to dhromed

    You didn't know 5+5 equals 11 for extremely large values of 5?

    /J

  • giannis (unregistered) in reply to Otto
    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.

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

Log In or post as a guest

Replying to comment #:

« Return to Article