- 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
No, I think it is a case of a badly formed employee.
Admin
That is very humorous - "isn't able to discern between ignorance and just lack of knowledge" - neither can I, since they are the same thing! http://dictionary.reference.com/search?q=ignorance
Admin
I submitted that php class I wrote to phpclasses.org to see if they'd actually accept a 150+ line class that just adds 2 numbers together...http://www.phpclasses.org/browse/package/2799.html LOL!
Admin
Clearly the issue is not that he'd never SEEN the += operator, but that he couldn't REMEMBER the += operator. He knew it existed (as it is essentially the "increment by" operator he's referring to), but didn't recall what it was. Noob behavior, to be sure, but not really "WTF"...
Admin
#define SIX 8 - 2 #define NINE 2 + 7
x += SIX * NINE;
Admin
<FONT face=Verdana size=2>Well, of course it has to be:</FONT>
<FONT face="Courier New">((((((((((i++)++)++)++)++)++)++)++)++)++)++</FONT>
[:D]
Admin
If you prefer something more canonical:
<font size="2"> #define SIX 1+5
#define NINE 8+1
printf("%d", SIX*NINE);
</font>
Sincerely,
Gene Wirchenko
Admin
I'm sure you mean
<font size="2"> #define NINE 8-1
</font>
Only then do you get the correct answer (though you may not like it). Even better:
<font size="2"> #define l -2 // correction factor
...
</font><font size="2"> #define NINE 8+l
</font>
Admin
Nope. My post stands. Remember to do the substitution first and that there are no brackets.
Sincerely,
Gene Wirchenko
Admin
Admin
HA! N3wb! </1337> Now go look up the postincrementation rules! And then read MY _informed_ post above where I do it *correctly*! ;) :p
Admin
Ah, serves me right for wandering unprepared into the murky depths of C preprocessor madness...
Admin
No one mentioned:
#!/usr/bin/ruby
i = 1
11.times {i+=1}
puts i
Admin
Yeah... some poor beg's gonna see it and use it somewhere. Next thing ya know... it'll show up here. But still, what a hoot.
Admin
What about... x = x + 11.
So damn simple.
Admin
WTF?
Admin
http://en.wikipedia.org/wiki/The_Answer_to_Life%2C_the_Universe%2C_and_Everything
Admin
Seriously, in that day and age and on this board, how's that possible?
Admin
Any technology sufficiently advanced is indistinguishable from a one-line Perl script:
perl -e '$i = shift; eval q($i++;) x 11; print $i' 31
(Windows users -- change the 's to "s)
Admin
Thank you for the kind words... [:#]
Did you really think I meant this??? Too bad for you if you did...
Admin
I'm surprised no one has shown how easy this is in Ruby!
11.times { i += 1 } i
Admin
except when i == 0 or (maybe) i < 0
Admin
The following does not increment by 11:
[code]
var x = 1;
for (var i = 0; i < 4; i++)
{
x += x
}
x -= 5
alert(x)
[/code[
Admin
int MyNumber;
//assign some value to MyNumber here
union PleaseIncreaseThisIntegerBy11
{
signed int number1;
unsigned int number2;
};
PleaseIncreaseThisIntegerBy11 PrettyPlease;
PrettyPlease.number2 = 4294967285;
MyNumber -= PrettyPlease.number1;
Admin
Sorry to bring up an old post, but
maybe (excuse the lack of proper c# but i'm fairly lazy)
sqlConnection sc=new sqlConnection ("blahblah blah server info blah blah");
sc.open();
for (int x=15; x>=5; --x)
new sqlcommand("insert into tablep", sc).executenonquery();
int ineed11=ineed11+int.parse(new sqlcommand("select count (*) from (select top 11 from tablep) q ", sc).executescalar().tostring())
//sc.close() //comment this out because closing connections is for chumps
Admin
x = ((x/11)++)*11
Admin
You'll need to cast it to a float for small numbers.
Admin
Here's my addition to the heap of obfuscation seen here (this is in PHP, and was indeed verified to work):
function add11to($i)
{
$i3 = $i; $i2 = $i;
while ($i++ != $i2+count(file(FILE)) - 1){
for($i4 = 0; $i4 <= $i2+count(file(FILE)) - 1; $i4++){
if ($i4 == $i2+count(file(FILE)) - 1) $i3++;
}
}
return $i3;
}
?>
Admin
bobo1on1: Huh?
Anonymous: (x/11) is not ++-able. On either side.
Admin
I was kinda replying to the comment about 'subtle floating point errors' from a previous page, sorry I wasn't more clear, and it should probably have been more like (x/11+1)*11 but I was too lazy to fire up a compiler...
In compensation, here is an example, that if I recall correctly would have worked in GW Basic:
x=x+(x=(x-11))*-11
Admin
Oh, I see... I was thinking integer arithmetic.
Admin
i += 11 - i;
Admin
((var / 11.0)++) * 11.0
Admin
double incr = 1.0/3
for (int c = 0; c < 33; c++) i += incr;
1.0/3 == 0.33333333333333331482961625624739
coudn't use the well known 1.0/10 because it would be slightly more (0.10000000000000000555111512312578) instead of less.
Admin
As you surely know, iteration is human, but recursion is godlike.
Note: This brilliant piece of code is based on a real homework task (Implement an adder by recursion!) we were assigned at Informatics class at my technical university where I study EE!Therefore, a much better way to increment i by 11 has to be implemented using recursion:
Admin
Sorry, my code somehow was cut off in the middle.
The full version is:
public class SimpleAdderByEleven {
private int add(int a, int b) throws Exception {
if ((a<0) || (b<0))
throw new Exception("Argument out of range");
if (b>0)
return add(increment(a),decrement(b));
else
return a;
}
public int incrementByEleven (int numberToBeIncrementedByEleven) throws Exception
{
try {
return add(eleven(),numberToBeIncrementedByEleven);
}
catch(Exception e) {
throw new Exception("Argument out of range");
}
}
private int generateEleven(int elevenSeed) {
if (elevenSeed < 11)
return(generateEleven(++elevenSeed));
else
return 11;
}
private int eleven(){
return generateEleven(0);
}
private int increment(int numberToBeIncremented) {
numberToBeIncremented = numberToBeIncremented + (eleven() / eleven());
return numberToBeIncremented;
}
private int decrement(int numberToBeDecremented) {
numberToBeDecremented = numberToBeDecremented - (eleven() / eleven());
return numberToBeDecremented;
}
Admin
omg, i think i found the real solution:
public void AddEleven(ref int value)
{
int tmp;
int add = 0;
List<int> list = new List<int>();
while(list.Count <= 11)
{
list.Add(1);
}
add = list.Count;
tmp = value + add;
value = tmp;
}
Admin
<FONT face="Courier New">int increment_by_eleven(int n) {</FONT>
<FONT face="Courier New"> double pivot = INT_MAX/2.0;
double x = rand(), old_x = n;</FONT>
<FONT face="Courier New"> while((x < old_x+10.999) || (x > old_x+11.1)) {
if(x < old_x+11) x += pivot;
else x -= pivot;</FONT>
<FONT face="Courier New"> pivot /= 2.0;
}
return (int)x;
}</FONT>
I think that's as close as anyone can get to the real value, from my tests I'm getting about 99.2% success rate. Who would have thought that binary search would finally pull through.
Admin
Nathan: Steve, you know how ++ will increment, right?
Steve: Right ....
Nathan: Okay, so how do you increment by 11?
Steve: Oh, that's a bit of a problem. At least the first part is easy, the second part's a problem, but not impossible.
Nathan: What's the first part?
Steve: Paste this into notepad and save it. Make sure the first text appears on the first line:
<FONT face="Courier New" size=2>\1+\v
|:-1<
>$@</FONT>
Nathan: Okay, so what's the second part?
Steve: You're going to have to write a befunge interpreter that allows you to populate the stack before you execute your script. Push the number you need to increment onto the stack, then push 11, then load your script and run it. Once it's finished, you can simply pop your answer right of the stack.
Nathan: Gee, thanks Steve, you're so much more helpful than that CS lecturer I had.
Admin
I can't believe nobody has yet come up with the obvious FORTH solution (using prime factors of 42, of course, and a small adjustment)...
<FONT face="Courier New">: plus11 ( i -- i ) 7 3 2 + + + 1 - ;</FONT>
Example:
<FONT face="Courier New">3 plus11 . 14 ok</FONT>
Tsh. Amateurs.
D.
Admin
The obvious solution is:
double incby(int x, int inc) { int32_t v2; // change to 64 bit if you have the time double v1; v1 = 0; v2 = inc; do{ while( fabs((v2 *= 16807)/2.e10 + 1.72e-9) > 0.1); v1 += v2/2.e10; //printf("%g\n",v1); =) }while( fabs(v1 - inc) > 1.e0);//change to 1.e-9 for extra fun return x + v1; }
If you really have the time, you can change error and random number generator ... there is no guarantee that this will work for ALL values of inc ^^
Admin
i made up a much easier to read version:
void* addOneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean(void* theValueToWhichWeWillAddOneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean)
{
int oneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean = 11;
int temporaryVariableWhichDoesntHaveAnyPurposeButToFillThatUpcomingForLoop = 0;
for(int one = 1; i <= oneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean; one++)
{
temporaryVariableWhichDoesntHaveAnyPurposeButToFillThatUpcomingForLoop++;
}
(int)theValueToWhichWeWillAddOneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean += oneMoreThanTenButAtTheSameTimeOneLessThanTwelveIfYouKnowWhatIMean;
if(thisIsCockyEnough)
{
return 0;
}
}
Admin
I think that the proper way to approach a situation like this involves the scripting language Lua. This sample generates 20002 lines of Lua script: int f(int n) { lua_State *L = lua_open(); std::ostringstream x; x << "function f(n)\n"; for(int i = -9999; i < 9999; ++i) x << "\tif(n == " << i << ") then return " << i + 11 << " end\n"; x << "error("PANIC")\nend\n"; luaL_loadstring(L, x.str().c_str()); lua_call(L, 0, 0); lua_getglobal(L, "f"); lua_pushnumber(L, n); lua_call(L, 1, 1); int r = lua_tonumber(L, -1); lua_pop(L, 1); // keep the stack clean lua_close(L); }
Admin
And for advanced programmers:
Just how do you increment 11 by 11 ?
Admin
<FONT face="Courier New" size=2>((</FONT></FONT><FONT face="Courier New"><FONT size=2><FONT style="BACKGROUND-COLOR: #ffffff" color=#0000ff>1</FONT><FONT color=#000000> </FONT><FONT color=#808030><<</FONT><FONT color=#000000> </FONT><FONT color=#008c00><FONT color=#0000ff>1</FONT></FONT></FONT></FONT><FONT color=#808030>
</FONT></FONT></FONT></FONT></FONT></FONT><FONT color=#008c00></FONT></FONT><FONT color=#008c00 size=2></FONT><FONT face="Courier New" size=2>)|</FONT></FONT><FONT face="Courier New"><FONT size=2><FONT color=#0000ff>1</FONT><FONT color=#000000> </FONT><FONT color=#808030>|</FONT><FONT color=#000000> </FONT><FONT color=#808030>( </FONT><FONT color=#0000ff>1</FONT></FONT></FONT><FONT color=#808030><FONT face="Courier New" size=2><<</FONT>
<FONT face="Courier New" size=2>((</FONT></FONT><FONT face="Courier New"><FONT size=2><FONT color=#0000ff>1</FONT><FONT color=#000000> </FONT><FONT color=#808030><<</FONT><FONT color=#000000> </FONT><FONT color=#0000ff>1</FONT></FONT></FONT><FONT color=#808030><FONT face="Courier New" size=2>)</FONT>
<FONT face="Courier New" size=2>|</FONT></FONT><FONT face="Courier New"><FONT size=2><FONT size=1><FONT size=2><FONT color=#000000> </FONT><FONT color=#0000ff>1</FONT><FONT color=#808030>)))<<</FONT><FONT color=#0000ff>1</FONT><FONT color=#800080>;
Admin
i just found the obvious solution!
try{
x+1=x;
}
catch (StupidCoderGenericError)
{
}
try{
x+1=x;
}
catch (StupidCoderGenericError)
{
}
try{
x+1=x;
}
catch (StupidCoderGenericError)
{
}
try{
x+1=x;
}
catch (StupidCoderGenericError)
{
}
try{
x+1=x;
}
catch (StupidCoderGenericError)
{
}
try{
x+1=x;
}
catch (StupidCoderGenericError)
{
}
try{
x+1=x;
}
catch (StupidCoderGenericError)
{
}
try{
x+1=x;
}
catch (StupidCoderGenericError)
{
}
try{
x+1=x;
}
catch (StupidCoderGenericError)
{
}
try{
x+1=x;
}
catch (StupidCoderGenericError)
{
}
try{
x+1=x;
}
catch (StupidCoderGenericError)
{
}
try{
x+1=x;
}
catch
{
//i'm doomed! can't do it!
}
i know it needs some brushing up, but the code is promising, right ????
Admin
meant x+11=x in the last post
Admin
Clearly, you should use the correct multi-threaded approach that vastly simplifies the complicated problem at hand.
You would create one thread that infinitly increments x, and another that stops the first thread after the correct amount of time.
I believe in Java, It could be written like this:
//Increments the variable
public class Incrementer {
private int temp;
//Does the function
public int doFunction(int x) {
temp = x;
final Thread adder = new Thread() {
public void run() {
while(true) temp++;
}
};
Thread stopper = new Thread() {
public void run() {
try {
int timeForOneIncrement = 1;
sleep(timeForOneIncrement * 11);
adder.stop();
} catch (InterruptedException e) {
/Do nothing, because performing any action that might notify the user something has gone wrong could be dangerous when an Exception has occured./
}
}
};
// Start The Threads!
adder.start();
stopper.start();
//Wait for the thread to stop
stopper.join();
adder.join();
//Return the incremented value
return temp;
}
}
Admin
Or,
//Javascript
eval(String.fromCharCode(120,32,61,32,120,32,43,32,49,49,59));
For those who prefer not to have any addition or equals signs, nor quotation marks.
And I would also like to see a brain fuck solution:
http://en.wikipedia.org/wiki/Brain_Fuck
Admin
Indeed. Haven't we all been in this situation?
So the coworker has taken the right approach, slipped a little on one statement, did a test (highly commendable!), did notice that the result could not possibly be right despite the simplicity of his code (very observant), and then stared at the problem until the code is now burned into his monitor and his retina.
The correct response is to tell him how to proceed in this situation: Take a break, walk around for 20 minutes, or tackle an entirely different (non-programming) problem.
The next cursory glance at the code will then result in a "D'oh" heard through the entire building.