Thread: Almost Daily Contest Details

  1. #29
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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:
    Quote Originally Posted by prog-bman
    Heres one write a program that outputs Your name in the most amount of lines

    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:
    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;
    }
    Because it's the shorter of the two. Compile and run this, and you'll get my answer, which weighs in at 899 lines, none of which are whitespace.

    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.
    Last edited by quzah; 09-19-2004 at 10:39 PM.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Almost Daily Contest Details
    By dagdarian in forum Contests Board
    Replies: 4
    Last Post: 01-25-2005, 05:03 AM
  2. Almost Daily Contest #4
    By Prelude in forum Contests Board
    Replies: 35
    Last Post: 08-25-2003, 08:54 AM
  3. Almost Daily Contest #3
    By Prelude in forum Contests Board
    Replies: 29
    Last Post: 08-16-2003, 08:48 PM
  4. Almost Daily Contest #2
    By Prelude in forum Contests Board
    Replies: 37
    Last Post: 08-09-2003, 10:51 PM
  5. Almost Daily Contest #1
    By Prelude in forum Contests Board
    Replies: 32
    Last Post: 08-05-2003, 08:34 AM