- 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
this is an inline Spinal Tap joke ...
Admin
Can someone explain the spinal tap thing please?
Admin
It depends how you define 'guy', and she's very definitely female now.
Admin
There's a scene in "This is Spinal Tap" where this guy is going on about how the gain knob on his amplifier goes up to "11" ...
Admin
That's one more.
Admin
In assembly:
add [i], 11
In C etc..
i = i+11;
Admin
Admin
er, that's i *= 11
Admin
Well, everybody else was posting incorrect solutions, so I figured why the not me too. [;)]
Still, if you want it to actually work:
Admin
I think a loop is a great solution for this! But yours was really too simple. Try this:
int ThisOneGoesToEleven(int x) {
int oldValue = x;
int newValue = oldValue;
int i = -11;
do {
oldValue = newValue;
newValue -= Math.Sign(i++);
} while (oldValue != newValue);
return newValue;
}
Hmm. I'm not sure if that's quite right. Perhaps the return statement should be changed to return x + (newValue - x)?
"The purpose of writing is to inflate weak ideas, obscure pure reasoning, and inhibit clarity. With a little pratice, writing can be an intimidating and impenetrable fog!"
-- Calvin (of Calvin and Hobbes)
Admin
Wow, a loop!? Unroll it really fast before somebody sees it! [:P]
Admin
Why not use a table lookup?
#define ARRAY 256
int table[ARRAY];
int TableFill(i)
{
for (int j = 0; j < ARRAY; j++) {
table[j] = i+j;
}
}
...
TableFill(i);
i = table(11);
...
Admin
Only until you wrap around the maximum value for i's data type. Maybe that's the point, to find out what maxint is on that system!
Admin
A recent 'Coding Horrors' essay about Dani Berry brought up the prevalence of transgen folk in the computer field. Unfortunately, the link to the page about TG software developers seems to be broken.
I seem to be running into the topic a lot lately, and not just because I am a regular reader of Venus Envy, El Goonish Shive, The Wotch, and From Then on Forth, either (I hope that Erin, Dan, Anne and Liz appreciate the plug). Given my own state of mind (and gender) right now, I'm more than a bit disturbed with the way the sychronicities are piling up. I can only conclude that Lady Eris is have a bit of fun with me. All Hail Discordia...
Admin
love the loop
int j = 0;
for (int i=0 ; i<11 ; i++, j++){}
Admin
void add(int a, int b) {
throw a + b;
}
try {
add(j, 11);
} catch (int result) {
j = result;
}
Admin
void addEleven(int i) {
i += 11;
}
Admin
Nah, you have to write an IncrementHandler class, with an Incrementer subclass, and in this case you would use the IncrementByEleven method. Right?
Admin
Admin
Easy…
for( int i = orig_var; orig_var < i + 11 ; ++orig_var );
Admin
lim(i + 11cos(x),x,0,1);
Limits and trigonometrics, do I win? :D
Admin
,>++++++[<-------->-]+++++++++++[<+>-]<.
Admin
Obviously its better if more of the computation can be done at compile time:
template < int amount > int increment( int n ) {
return increment<amount - 1>(n) + 1;
}
template <> int increment <0> ( int n ){
return n;
}
Admin
most of the template didnt survive the post... this is my last attempt.
template < int amount > int increment( int n ) {
return increment<amount - 1>(n) + 1;
}
template <> int increment <0> ( int n ){
return n;
}
Admin
omg, you actually took the time to do that! :)
Admin
Pfft, philistines.
(defun increment-by-11 (x)
(funcall #'(lambda (x) (+ 11 x)) x))
Admin
>> Nathan: Okay, so how do you increment by 11?
It's so that simple! we can design a wonderful disposition, like this:
++++
+ i ++
++++
LOL
Admin
The comment one was the best...lost it in my clipboard but it was something like this.
i+=3; // increment by 11
[:D]
Admin
well,
5 pages of comments and nobody has yet posted a solution in l33t:
http://en.wikipedia.org/wiki/L33t_programming_language
a11 ppl 4r3 d3f1n1t3lY n07 lE3t Th1nk0rZ!
And this program includes a complete user interface!
Admin
create table #tbl (num int)
declare @i int
set @i=0
WHILE @i <=11
BEGIN
INSERT #tbl VALUES (@i)
set @i=@i+1
end
select top 1 * FROM #tbl
order by num desc
drop table #tbl
Admin
<font size="3">There haven't been enough solutions with randomized data...As an added bonus, I included error handling.
Dim i As Integer
i = InputBox("Enter Int:","I R TEH C0D3R")
On Error GoTo Add
i = i / 0
Exit Function
Add:
Randomize (Time)
Dim temp As Integer
temp = i + 11
While i <> temp
If i < temp Then i = i + (Rnd * 7)
If i > temp Then i = i - (Rnd * 7)
Wend
</font>
Admin
0 CLS
10 numo = 0
20 i = 0
30 FOR i = 10 TO 0 STEP -1
40 LET numo = numo + 1
50 NEXT i
60 LPRINT numo
70 GOTO 60
80 END
Admin
#define ELEVEN 12
#define MAGICNUMBER 39
void addNum(int * a, int b)
{
*a^=b;
b=((*a^b)&b)<<1;
if(b)
addNum(a,b);
}
struct addByElevenStruct
{
int magicnumber;
int multiplier;
int number;
};
//Note, when you want to add 11 to MAGICNUMBER remember to use the userfriendly
//addByEllevenStruct interface
//Hell, just choose a good magic number like 39! Who would ever think of adding
//11 to 39?
void addByEleven(int * a)
{
int usingmagic = 0;
int multiplier=1;
int number=*a;
int carry;
if(number==MAGICNUMBER)
{
multiplier=((struct addByElevenStruct *)a)->multiplier;
number=((struct addByElevenStruct )a)->number;
usingmagic=1;
}
if(number==0)
{
if(!usingmagic)
a=ELEVEN;
else
((struct addByElevenStruct )a)->number=ELEVEN;
}
else
{
struct addByElevenStruct str;
str.magicnumber = MAGICNUMBER;
str.multiplier = multiplier2;
carry = number%2;
str.number = number/2;
addByEleven((int)&str);
str.number = str.number+carrymultiplier;
if(!usingmagic)
*a=str.number;
else
((struct addByElevenStruct *)a)->number=str.number;
}
}
.
.
.
addByEleven(&j);
There is a bug left somewhere in the code as an excersie for the reader
Admin
I'd suggest doubling, de-elevenation, ++-ing, then elevenation and undoubling:
i = (++(((double)i) / 11)) * 11;
Admin
// increment 'i' by 'j'
HRESULT Increment(int i, int j, int *pOut)
{
// TODO: handle the "11" case.
if (j != 1)
{
return E_NOTIMPL;
}
i++;
*pOut = i;
return S_OK;
}
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
<FONT style="BACKGROUND-COLOR: #ffff00" face=Verdana size=6>+11</FONT>
Admin
class Fixnum
def method_missing(m)
if n = /inc_by(_)?(\d+)/.match(m.to_s)[2].to_i
self+n
end
end
end
puts 1.inc_by_11
puts 2.inc_by_20
puts 3.inc_by55
Admin
I love how people are making fun of the original coder and yet posting incorrect solutions.
The first one will not work because you can't put i++++. In C++ terms, i++ returns a temporary integer, and you can't increment it like that. Even if you could, it wouldn't change i. ++++i works because ++i returns a reference to i.
The second one, at least if it's C or C++, is undefined.
Admin
Hey, this is actually a difficult question.
Can someone do this using a first order logic solver? Deduce from a set of aksioms the answer to i + 11. Satisfiing this problem in a acceptable time could be tricky.
Admin
The second one owns j00.
Admin
while (i = i + 11) {break;}
Admin
<FONT size=6>Verbing weirds language</FONT>
<FONT size=2>Calvin and Hobbes</FONT>
Admin
for</FONT><FONT size=2> (</FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> j = 11; j > 0; j--, i++) ;
</FONT>Admin
*one* statement, please!
++i,i++,++i,i++,++i,i++,++i,i++,++i,i++,++i;
Admin
whoever didn't think of this si an idiot (java)
int i;
int j=i;
while(i!=j+11)
i=Math.random();
Admin
Here is a C# method, AddEleven, which may be used to increment a positive integer by 11. It uses a helper method, called Parse.
-----------------------------
private int AddEleven(int x)
{
string X;
return
Parse(int.Parse("0"+(X=x.ToString())[X.Length-1]))+
int.Parse(Parse(int.Parse("0"+X.Substring(0,X.Length-1))).ToString()+"0");
} // AddEleven
private int Parse(int x)
{
string X;
return
int.Parse(
char.IsNumber((char)(1+(int)(X=x.ToString())[X.Length-1]))?
X.Substring(0,X.Length-1)+(char)(1+(int)X[X.Length-1]):
Parse(int.Parse("0"+X.Substring(0,X.Length-1))).ToString()+"0"
);
} // Parse
-----------------------------
--
Clive
Admin
i ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++;
Admin
#include <stdio.h>
typedef struct eleven { char x [11] } * evil ;
int main ( char * argv[], int argc)
{
long x;
x = 1;
x = (long)((evil) x + 1);
printf(" X = %ld\n",x);
}
produces
X = 12
And variants like this have appeared in mine and colleagues code. Add some preprocessor wrapping and this kind of thing gets lost...
Admin
This is a humor site.
Nobody cares about your leet C standard skillz.
Stop it.