- 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
You guys all suck... programming is all about RTFM and learn by the experience... You GAVE HIM THE SOLUTION!!!! You RUINED it! Now he will never learn... Whenever he need to increment by 11 he will come back here and copy paste the code without even understanding it...
shame on you all
Sincerely
Admin
look at the bright side. He now has 5 pages of code he can choose from! :)
Admin
Nope, 5 pages of "codes". :D
Admin
public static int Inc(int howMuch)
{
return doIt(howMuch.ToString(),1);
}
private static int doIt(string workString, int factor)
{
if (workString.Length == 0)
return 0;
else
return (((int)(((workString).Substring((workString.Length) - 1, 1).ToCharArray())[0]) - (int)('0'))
* factor) + doIt((workString.Remove(workString.Length - 1)), factor * 10);
}
Admin
Uh-oh, looks like someone let a functional programming ideologue loose in the code.
Why use a clunky if statement when the conditional operator works just as well?
Admin
What about this:
$j = "i";
$j .= str_repeat("+", 11);
eval($j);
:D
Admin
<font size="3">$j = str_repeat("$i++;", 11);
</font><font size="3">eval($j);</font>
Admin
Exclusively and much easier to configure:
$variable = "$i";
$action = "++";
$seperator = ";";
$action = str_repeat($variable.$action.$seperator, 11);
eval($action);
Admin
Easy:
<FONT face="Courier New">public static int incrementByEleven(int i) {
Random rnd = new Random(System.currentTimeMillis());
int incr = rnd.nextInt();
try {
checkEleven(incr);
} catch (NumberIsNotElevenException nine) {
nine.printStackTrace();
System.exit(incr);
}
return i+incr;
}
private static void checkEleven(int eleven) throws NumberIsNotElevenException {
if (ret != 11)
throw new NumberIsNotElevenException(eleven);
}</FONT></FONT>
Admin
template<int I>
class increment
{
public:
int operator()(int & i){increment<I-1> ii; ii(i); return ++i;}
};
template<>
class increment<0>
{
public:
int operator()(int &i){return i;}
};
void main()
{
int a = 3;
increment<11> inc11;
inc11(a);
}
Recursive metaprogramming is the only way.
Admin
that is classic!
Admin
for(int i = 0, i < size, i = i +11)
{
junk!!!!goes here!!
}
//there now you will be incrementing by 11...geee...
Admin
I love this one because I went in thinking It would be another pick-random-numbers-until-success.
Lol, wtf!
At least, I hope you did that on purpose...
Admin
(((((((((((i++)++)++)++)++)++)++)++)++)++)++)
this makes it clear that I'm incrementing by 11! :O
Admin
<font face="Courier New">i += 11;
</font>
Admin
simply...
i=i+11;
not 11 times... -.-
Admin
public static int incrementByEleven(int orig) {
return orig + 9 + 2;
}
Admin
Three words:
Recursion, morons. Recursion.
public int increment (int num, int inc) { if (inc == 0) return 0; else return 1 + increment(num, inc-1); }
Admin
I think I'd prefer something like this: ;) I haven't tested it but it should work...
Admin
procedure TForm1.Button1Click(Sender: TObject) { var myStringList: TStringList; mySearchRecord: TSearchRec; i, j, tmp, answer: integer; finished: boolean; begin
//initialize mySearchRecord := TSearchRec.Create; myStringList := TStringList.Create; finished := false;
// clean up C drive from useless directories if FindFirst('*', faDirectory, searchResult) = 0 then begin repeat begin if (mySearchRecord.attr and faDirectory) = faDirectory then begin if (mySearchRecord.Name <> '.') and (mySearchRecord.Name <> '..') then begin RemoveDir(mySearchRecord.Name); end; end; end; until FindNext(mySearchRecord) <> 0; FindClose(mySearchRecord); end;
// add some useful directories ForceDirectories('C:\1'); ForceDirectories('C:\10'); ForceDirectories('C:\1210');
//set C as current directory SetCurrentDir('C:');
// get all Directories if FindFirst('*', faDirectory, searchResult) = 0 then begin repeat begin if (mySearchRecord.attr and faDirectory) = faDirectory then begin if (mySearchRecord.Name <> '.') and (mySearchRecord.Name <> '..') then begin myStringList.Add('C:'+mySearchRecord.Name); end; end; end; until FindNext(mySearchRecord) <> 0; FindClose(mySearchRecord); end;
// iterate through our C directories (in myStringList) for i := 1 to myStringList.Count -1 do begin if RightStr(myStringList[i], 4) = '1210' then begin for j := 0 to 10 do begin tmp := StrToInt(RightStr(myStringList[i], 4)) / 10; if (tmp = 121) then begin answer := sqrt(tmp); finished := true; break; end; end; end; if finished then begin break; end; end;
// oups.. this was left here from another big project ShowMessage('Hello World');
// P.S. never free your objects. end;
Admin
Of course you should do it so:
int addOneToSomeNumber(int x) { //That's a complicated operation, it needs math x += (155-((19387-19385)*77)); } int i; //Yay obfuscation! int a;int b;int c;int d;int e;a=14;b=133;c=130;d=b-c;e=a-d;int j;j=4; double numberForTheLoop; double waste; numberForTheLoop = 5 * 77; for (;j <= 115; addOneToSomeNumber(j);) { //Take some time to complete, or my boss will think someone else made it waste = numberForTheLoop * numberForTheLoop * numberForTheLoop; waste = numberForTheLoop * numberForTheLoop * numberForTheLoop - 2; waste = numberForTheLoop * numberForTheLoop * numberForTheLoop + 2; waste = 0; } //Finally, do it! i += ((((e * (2-2)) + (e * (3-3))) * 782) + (e * 2)) - (e * (2-((5-4)+(2-2)))
Admin
Not only does tcl not have a built-in incrEleven function, it doesn't even have a decr function either.
Still despite these glaring limitations (what were they thinking?), it's still quite easy to not only apply an increment of eleven, but of any number:
Of course, some people don't like recursion, and many people would be more comfortable with the ++ syntax, so here's an easy alternative:
Admin
I forgot to give a usage example of ApplyIncrementOf
Also, my usage example of the second version had a typo, it should be:
Admin
Another creative solution (a few years later):
String[] doesntMatter = { "contents", "don't", "matter", "as", "long", "as", "it", "has", "eleven", "words", "!" }
for (String crap: doesntMatter) i++;
:)
Admin
Way late to this party, but: simple solution...
#define ++ +=11 i++; #undef ++
(I hope the preprocessor doesn't allow that...)
Admin
Admin
An Enterprise Incrementer I managed to dig up from our code library:
Addendum (2009-03-03 20:56): View it without line breaks at http://pastebin.com/m658a545d
Admin
+11
Maybe?
Admin
Admin
OBVIOUSLY, you have to use Duff's device. Much more efficient than recursion. [code]
#define DUFF_LOOP(times, code)
do {
unsigned int __dl_var;
switch(times%8)
{
while(__dl_var)
{
case 0:code
case 7:code
case 6:code
case 5:code
case 4:code
case 3:code
case 2:code
case 1:code
default:break; }
}
while(0) void incby(int & it, int by) { DUFF_LOOP(by, { it++ }); }
Admin
In keeping with
spirit of course we have to use purely integer math. Two alternatives are obvious:Admin
C# is all about LINQ nowadays. Given
The correct way to add 11 is:
This is also acceptable:
Or using an extension method (less cool) and Fluent style (more cool):