- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
All I can say to this is....
<font size="5">BRILLANT!</font>
Admin
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.
Admin
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);
Admin
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).
Admin
nice try but that only adds on 10
inc(int i) {
int j = 11;
do {
i++;
} while(--j);
}
Admin
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]
Admin
Amazing suggestions.
R.Flowers, Lobachevsky, and Cheem get my votes.
Admin
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-)]
Admin
While (I < I + 11)
{
I++;
}
Admin
<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>
Admin
Hmm, I think I should have used the word accuracy instead of precision. Oh well, make that change mentally if you use it, k?
Admin
I put an example of it's use here:
http://www.flobi.com/test/floIncrementor/
Admin
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.
Admin
<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
Admin
x += 10.9?
Admin
"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...>
Admin
#pragma pack(1) struct foo { char bumper[11]; }; ++(struct foo*)x;
Admin
Oops:
#pragma pack(1) struct foo { char bumper[11]; }; ++(struct foo*)&x;
Admin
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!
Admin
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...
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. ;)
Admin
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
Admin
/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.
Admin
Even if he's never seen +=. He's probably i = i + 11... Which is the same thing...
Admin
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.
Admin
There's the first WTF
Admin
A JavaScript solution would be something like this:
Hope this helps Steve... [8-|]
Admin
<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.
Admin
while(i!=i+11, i++)
Admin
That'll keep Nathan busy...
Admin
i = 10*((i/10)+1) + (i%10+1)
Admin
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.)
Admin
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.
Admin
Just use " x += 11.0;" and use a Pentium. The Pentium should look after the 'almost'.
Admin
Same
Admin
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.
Admin
I'll bet this guy learned to program in brainf**k.
Admin
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.
Admin
The end of that loops is supposed to be
$s /= ($s < 10) ? -atan(--$s) : $s*$s/2; }
of course.
Admin
i += pow(2.0,3.459)
</FONT>Admin
You do it like this:
int rest = 11;
do { int dummy = x & rest; x |= rest; rest = dummy << 1; } while (rest);
Admin
What kind of operator is |=?
Admin
Combined bitwise OR and assignment.
Admin
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 ).
Admin
That one sucks with backward compatibility. Here, this one's better:
Admin
Admin
This would have to be the best solution i have seen in a long time.
does it close the calculator though?
Admin
I really am dumb today. That should have been x^= rest, not x |= rest. Exclusive or, not simple or.
Admin
Hmm. Is that an actual framework, or some psudo-code? Looks like .NET, but more intuitive? Actually looks like Windows Script Host meets .NET.
Admin
You didn't know 5+5 equals 11 for extremely large values of 5?
/J
Admin
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.