let's see some almost daily contests people... I am ready to code!!! :D
Printable View
let's see some almost daily contests people... I am ready to code!!! :D
Heres one write a program that outputs Your name in the most amount of lines ;)
Code:#include<iostream>
#include<string>
using namespace std;
string repeat_forever(const string& name)
{
cout << name << endl;
return repeat_forever(name);
}
int main()
{
string name;
cout <<"\n\nEnter your name: ";
cin >> name;
repeat_forever(name);
return 0; //like this will ever happen
}
t'is done. :cool:
That won't work. You'll get a stack overflow, and the program will crash before eternity arrives ;)
And I think the point was to make a program that does nothing except print your name once, and to do it in the maximum amount of code lines. I'll have to think about this for some time...
Yes that is what I meant hunter good luck ;)
You do realize, it's possible to create such a program with the number of lines limited only by the space on your harddrive, if you do:
if(0)
else
if(0)
else
if(0)
else
...
cout << "Hunter2";
or even
;
;
;
;
...
cout << "hunter2"
**EDIT**
Perhaps the rules should include "lines must be required for program to function properly". Also include, "lines may not be broken unnaturally unless their length exceeds (x) non-whitespace characters; and identifiers may not exceed (x) characters in length". And, for good measure, "Exploits of any miswording in the rules will be punished by a warning and then immediate disqualification" :)
This is too easy. Here is my "short" version:
Now, I'm making an assumption on the character set, but I suspect I could do it without the assumption in pretty much the same way.Code:#include <stdio.h>
int main( void )
{
putchar(1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
+1+1+1+1);putchar(1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
+1+1+1+1+1+1+1+1+1+1+1+1+1);putchar(1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1);putchar(1+1+1+1+1+1
+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1);putchar(1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
+1+1+1+1+1+1+1+1+1+1+1+1);
return 0;
}
Like I said, this is the "short" version. With simple math, you could have an infinitely long file, just printing the first character.
[edit]
You'll notice a bug I've mentioned before, that this editor/vboard has. The whitespace column does not exist in my actual code or post. And there is no way to get rid of it.
[/edit]
[edit2]
I also used the full 80 column width, just to make sure I wasn't "cheating" by making my lines too short. ;) Also, people with longer names have an advantage...
[/edit2]
Quzah.
>>With simple math, you could have an infinitely long file, just printing the first character.
Well, perhaps a 'no backtracking' rule could be introduced, although the proper wording of such a rule eludes my consciousness at the moment :D
**EDIT
Hmm... you could do an extremely long one without backtracking by using floating-point numbers. Any ideas on a better rule? :rolleyes:
Define backtracking. You could start at a large number, and subtract one. Or, if that's backtracking, you could start at a very small negative number, and add one. All I did is start at one and increment. I'm not sure how that would be backtracking.
Quzah.
>>All I did is start at one and increment. I'm not sure how that would be backtracking.
It wasn't, I'm referring to +1-1+1-1+1-1+1-1 forever.
>>Define backtracking.
As I said, I can't think of any solid rule that would work. Unless you just say "Backtracking isn't allowed, and if we consider your code to be backtracking then you're out" ;) Or you could maybe just say that "Infinity exploits are disallowed".
Yeah, that was my first idea. ;) I was also going to post a modification of the above:Quote:
It wasn't, I'm referring to +1-1+1-1+1-1+1-1 forever.
There are all sorts of little things you can do. The above should take up 3x the space of my previous. :DCode:int q=0, u=0, z=0, a=0, h = 0;
q=q+1;q=q+1;q=q+1; ... putchar( q );
u=u+1; ...
...
Quzah.
Well, isn't that the point of the 'contest'? Come on quzah, let's see your ultimate :)
Here, I tried not to use any excesive spacing. And I could have done the 1 + 1 + 1 + 1 thing in here but I didnt want to steal quzahs idea
Code:#include <iostream>
int main ( void )
{
char name_char_1;
char name_char_2;
char name_char_3;
char name_char_4;
char name_char_5;
char name_char_6;
char name_char_7;
int name_var_1;
int name_var_2;
int name_var_3;
int name_var_4;
int name_var_5;
int name_var_6;
int name_var_7;
name_char_1 = 'V';
name_char_2 = 'i';
name_char_3 = 'c';
name_char_4 = 'i';
name_char_5 = 'o';
name_char_6 = 'u';
name_char_7 = 's';
name_var_1 = 0;
name_var_2 = 0;
name_var_3 = 0;
name_var_4 = 0;
name_var_5 = 0;
name_var_6 = 0;
name_var_7 = 0;
do {
name_var_1 ++;
}
while ( name_var_1 < name_char_1 );
do {
name_var_2 ++;
}
while ( name_var_2 < name_char_2 );
do {
name_var_3 ++;
}
while ( name_var_3 < name_char_3 );
do {
name_var_4 ++;
}
while ( name_var_4 < name_char_4 );
do {
name_var_5 ++;
}
while ( name_var_5 < name_char_5 );
do {
name_var_6 ++;
}
while ( name_var_6 < name_char_6 );
do {
name_var_7 ++;
}
while ( name_var_7 < name_char_7 );
std::cout <<
static_cast <char> ( name_var_1 );
std::cout <<
static_cast <char> ( name_var_2 );
std::cout <<
static_cast <char> ( name_var_3 );
std::cout <<
static_cast <char> ( name_var_4 );
std::cout <<
static_cast <char> ( name_var_5 );
std::cout <<
static_cast <char> ( name_var_6 );
std::cout <<
static_cast <char> ( name_var_7 );
std::cout << std::endl;
std::cin.get();
return 0;
}
I've imposed some limits for myself:
1) Lines that are not variable declarations, #includes, function prototypes,
or definitions, will be if possible, 80 characters in width.
2) To make this the same for everyone trying it, I will output what is suggested:
:DQuote:
Originally Posted by prog-bman
This way, everyone outputting Your name will all be using the same length item. Otherwise I could create an account with the longest name allowable, consisting of the character with the highest ascii value... ;)
3) I'll restrict (;)) my variable names to the length allowed for externally linked variables in C99. That is to say, 31 characters.
4) I will use only four spaces for indenting.
5) I'll use no unnecessary whitespace-only lines.
6) I'll assume the ascii character set.
Rather than just post the code itself, I wrote a program to make the program for me. Here is its source code:
Because it's the shorter of the two. :D Compile and run this, and you'll get my answer, which weighs in at 899 lines, none of which are whitespace.Code:#include <stdio.h>
#include <stdlib.h>
void fpvar( FILE *fp, int c )
{
char prefix[] = "ThisIsTheVariableForThe";
char *suffix[] = { "Letter_", "OneSpace" };
fprintf( fp, "%s%s", prefix, suffix[c==' '?1:0] );
if( c != ' ' )
{
fprintf( fp, "%c", c );
}
}
int main( void )
{
int x,y,z;
char letters[] = "Your name";
char *lines[] =
{
"#include <stdio.h>\n",
"int main( void )\n",
"{\n",
" char ",
" ",
" ",
" return 0;\n",
"}\n",
0,
};
FILE *fp = fopen("yourn.c", "w" );
if( !fp )
return 0;
for( x = 0; lines[x]; x++ )
{
fprintf( fp, "%s", lines[x] );
if( x == 3 )
{
fpvar( fp, letters[0] );
fputs( "=0,", fp );
fpvar( fp, letters[1] );
fputs( "=0,\n", fp );
}
if( x == 4 )
{
for( y = 0; y < 5; y+=2 )
{
fpvar( fp, letters[y+2] );
fputs( "=0,", fp );
fpvar( fp, letters[y+3] );
fputs( "=0,\n", fp );
fputs( lines[x], fp );
}
fpvar( fp, letters[y+2] );
fputs( "=0;\n", fp );
}
if( x == 5 )
{
for( y = 0; letters[y]; y++ )
{
for( z = 0; z < letters[y]; z++ )
{
fpvar( fp, letters[y] );
fputc( '=', fp );
fpvar( fp, letters[y] );
fputs( "+1;\n", fp );
fputs( lines[x], fp );
}
fputs( "putchar( ", fp );
fpvar( fp, letters[y] );
fputs( " );\n ", fp );
}
}
}
fclose( fp );
return 0;
}
Once I had the idea of what to do, it was funner to write a program to write it for me, than it was to actually write the output myself. :)
[edit] Minor pedantic editing. [/edit]
Quzah.
Un-freaking-believeable....
Good job.