World Smallest Program

Discussion in 'C Programming' started by CK, Jul 19, 2005.

  1. CK

    CK Guest

    Hi EveryBody!
    This is the World Smallest Program in c.

    main(l
    ,a,n,d)char**a;{
    for(d=atoi(a[1])/10*80-
    atoi(a[2])/5-596;n="@NKA\
    CLCCGZAAQBEAADAFaISADJABBA^\
    SNLGAQABDAXIMBAACTBATAHDBAN\
    ZcEMMCCCCAAhEIJFAEAAABAfHJE\
    TBdFLDAANEfDNBPHdBcBBBEA_AL\
    H E L L O, W O R L D! "
    [l++-3];)for(;n-->64;)
    putchar(!d+++33^
    l&1);}

    by
    CK
     
    CK, Jul 19, 2005
    #1
    1. Advertising

  2. CK wrote:
    > Hi EveryBody!
    > This is the World Smallest Program in c.


    Obviously not, for at least two reasons.
     
    Martin Ambuhl, Jul 19, 2005
    #2
    1. Advertising

  3. CK

    Chris Hills Guest

    In article <>, CK
    <> writes
    >Hi EveryBody!
    >This is the World Smallest Program in c.
    >
    >main(l
    >,a,n,d)char**a;{
    >for(d=atoi(a[1])/10*80-
    >atoi(a[2])/5-596;n="@NKA\
    >CLCCGZAAQBEAADAFaISADJABBA^\
    >SNLGAQABDAXIMBAACTBATAHDBAN\
    >ZcEMMCCCCAAhEIJFAEAAABAfHJE\
    >TBdFLDAANEfDNBPHdBcBBBEA_AL\
    >H E L L O, W O R L D! "
    >[l++-3];)for(;n-->64;)
    >putchar(!d+++33^
    >l&1);}
    >
    >by
    >CK
    >


    int main(int var)
    (
    return(var +1)
    )

    --
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
     
    Chris Hills, Jul 19, 2005
    #3
  4. CK

    Suman Guest

    Chris Hills wrote:
    > In article <>, CK
    > <> writes
    > >Hi EveryBody!
    > >This is the World Smallest Program in c.
    > >
    > >main(l
    > >,a,n,d)char**a;{
    > >for(d=atoi(a[1])/10*80-
    > >atoi(a[2])/5-596;n="@NKA\
    > >CLCCGZAAQBEAADAFaISADJABBA^\
    > >SNLGAQABDAXIMBAACTBATAHDBAN\
    > >ZcEMMCCCCAAhEIJFAEAAABAfHJE\
    > >TBdFLDAANEfDNBPHdBcBBBEA_AL\
    > >H E L L O, W O R L D! "
    > >[l++-3];)for(;n-->64;)
    > >putchar(!d+++33^
    > >l&1);}
    > >
    > >by
    > >CK
    > >

    >
    > int main(int var)
    > (
    > return(var +1)
    > )
    >

    ....and this compiles on? Not with my gcc 4.0.0 though!
    BTW: what's wrong with int main(){} ?
     
    Suman, Jul 19, 2005
    #4
  5. CK

    Guest

    CK wrote:
    > Hi EveryBody!
    > This is the World Smallest Program in c.
    >


    ???? In what sense, it is worlds smallest? and what does it do?

    -santosh
     
    , Jul 19, 2005
    #5
  6. CK

    Richard Bos Guest

    Chris Hills <> wrote:

    > In article <>, CK
    > <> writes
    > >This is the World Smallest Program in c.
    > >
    > >main(l
    > >,a,n,d)char**a;{

    [ Snip ten more lines ]

    > int main(int var)
    > (
    > return(var +1)
    > )


    Well, it's just as much the smallest, and just as much a C program.

    The answer, perhaps surprisingly (or perhaps not) is different for C89
    and for C99. Guess which is smaller?

    Richard
     
    Richard Bos, Jul 19, 2005
    #6
  7. CK

    Suman Guest

    Richard Bos wrote:
    > Chris Hills <> wrote:
    >
    > > In article <>, CK
    > > <> writes
    > > >This is the World Smallest Program in c.
    > > >
    > > >main(l
    > > >,a,n,d)char**a;{

    > [ Snip ten more lines ]
    >
    > > int main(int var)
    > > (
    > > return(var +1)
    > > )

    >
    > Well, it's just as much the smallest, and just as much a C program.
    >
    > The answer, perhaps surprisingly (or perhaps not) is different for C89
    > and for C99. Guess which is smaller?
    >

    Guess what, I was going to append the gcc call that I used
    (blame it on hubris or what you will):
    gcc -std=c99 -Wall -pedantic -ansi test.c

    AFAIR, there's no falling-off of main in C89. Is that what you mean?
     
    Suman, Jul 19, 2005
    #7
  8. CK

    Rob Morris Guest

    wrote:
    >
    > CK wrote:
    >
    >>Hi EveryBody!
    >>This is the World Smallest Program in c.
    >>

    >
    >
    > ???? In what sense, it is worlds smallest? and what does it do?
    >
    > -santosh
    >

    It's not the world's smallest, it's the "World Smallest"

    Call it with 2 or more arguments, and it prints out a little text world
    map, though I'm not sure how portable it is. I'm sure we've all written
    little text-picture-encoded-in-a-string programs, but I found it a
    fairly amusing post.

    --
    Rob Morris: arr emm four four five (at) cam dot ac dot uk
     
    Rob Morris, Jul 19, 2005
    #8
  9. CK

    Richard Bos Guest

    Rob Morris <> wrote:

    > wrote:
    > >
    > > CK wrote:
    > >
    > >>This is the World Smallest Program in c.

    > >
    > > ???? In what sense, it is worlds smallest? and what does it do?

    >
    > It's not the world's smallest, it's the "World Smallest"
    >
    > Call it with 2 or more arguments, and it prints out a little text world
    > map, though I'm not sure how portable it is. I'm sure we've all written
    > little text-picture-encoded-in-a-string programs, but I found it a
    > fairly amusing post.


    But it still isn't the smallest, nor print the smallest. This does:

    #include <stdio.h>
    int main(void){puts(".");}

    C99, of course. And it's a _very_ small world map.

    Richard
     
    Richard Bos, Jul 19, 2005
    #9
  10. In article <4all.nl>,
    Richard Bos <> wrote:
    >Chris Hills <> wrote:
    >
    >> In article <>, CK
    >> <> writes
    >> >This is the World Smallest Program in c.
    >> >
    >> >main(l
    >> >,a,n,d)char**a;{

    >[ Snip ten more lines ]
    >
    >> int main(int var)
    >> (
    >> return(var +1)
    >> )

    >
    >Well, it's just as much the smallest, and just as much a C program.


    If you print the first one in flyspeck-3 and the second one in a
    readable font, you might be able to miss little details like that for
    the first one.


    >The answer, perhaps surprisingly (or perhaps not) is different for C89
    >and for C99. Guess which is smaller?


    That would be "It depends", if I'm not mistaken. Do we have to have a
    sensible return value?

    In no specified order:
    --------
    main(){}
    --------
    int main(){}
    --------
    main(){return 0;}
    --------
    Depending on implementation-defined (or is it unspecified?) aspects of
    the implementation used to implement the implementation you're using
    (if I'm not mistaken and haven't confused myself putting that clause
    together), you may or may not be able to get away with dropping the
    newline after the `}'.


    dave
    (now how 'bout "smallest doing something useful"?)

    --
    Dave Vandervies

    Writing a C program is one possible way to do it.
    --Richard Heathfield answers a poorly disguised homework question in CLC
     
    Dave Vandervies, Jul 19, 2005
    #10
  11. In article <>,
    CK <> wrote:
    > Hi EveryBody!
    > This is the World Smallest Program in c.
    >
    > main(l
    > ,a,n,d)char**a;{
    > for(d=atoi(a[1])/10*80-
    > atoi(a[2])/5-596;n="@NKA\
    > CLCCGZAAQBEAADAFaISADJABBA^\
    > SNLGAQABDAXIMBAACTBATAHDBAN\
    > ZcEMMCCCCAAhEIJFAEAAABAfHJE\
    > TBdFLDAANEfDNBPHdBcBBBEA_AL\
    > H E L L O, W O R L D! "
    > [l++-3];)for(;n-->64;)
    > putchar(!d+++33^
    > l&1);}


    I'm guessing that it's not original. Possibly it was
    originally an IOCCC entry and formatted like so:

    main(l
    ,a,n,d)char**a;{
    for(d=atoi(a[1])/10*80-
    atoi(a[2])/5-596;n="@NKA\
    CLCCGZAAQBEAADAFaISADJABBA^\
    SNLGAQABDAXIMBAACTBATAHDBAN\
    ZcEMMCCCCAAhEIJFAEAAABAfHJE\
    TBdFLDAANEfDNBPHdBcBBBEA_AL\
    H E L L O, W O R L D! "
    [l++-3];)for(;n-->64;)
    putchar(!d+++33^
    l&1);}

    [fixed-width font required]

    Such that the program itself resembles the world. I suspect
    that the original author would not have been so quick to
    remove the indentation.

    http://www.ioccc.org/1992/westley.c
    --
    7842++
     
    Anonymous 7843, Jul 19, 2005
    #11
  12. CK

    Richard Bos Guest

    (Dave Vandervies) wrote:

    > In article <4all.nl>,
    > Richard Bos <> wrote:
    > >The answer, perhaps surprisingly (or perhaps not) is different for C89
    > >and for C99. Guess which is smaller?

    >
    > That would be "It depends", if I'm not mistaken. Do we have to have a
    > sensible return value?


    Well, yes, of course. Otherwise, we could just leave it empty and claim
    that "Link: no such function as main()" is the output of our program.

    > (now how 'bout "smallest doing something useful"?)


    Ah, now there's a mare's nest. How does one define "useful"? Always
    returning zero could be useful in some circumstances, for example as a
    stub in makefiles.

    Richard
     
    Richard Bos, Jul 20, 2005
    #12
  13. On Wed, 20 Jul 2005 15:07:45 GMT, Richard Bos
    <> wrote:

    > (Dave Vandervies) wrote:
    >
    >> In article <4all.nl>,
    >> Richard Bos <> wrote:
    >> >The answer, perhaps surprisingly (or perhaps not) is different for C89
    >> >and for C99. Guess which is smaller?

    >>
    >> That would be "It depends", if I'm not mistaken. Do we have to have a
    >> sensible return value?

    >
    > Well, yes, of course. Otherwise, we could just leave it empty and claim
    > that "Link: no such function as main()" is the output of our program.
    >
    >> (now how 'bout "smallest doing something useful"?)

    >
    > Ah, now there's a mare's nest. How does one define "useful"? Always
    > returning zero could be useful in some circumstances, for example as a
    > stub in makefiles.


    true.c:

    int main(void) {return 0;}

    Very useful in Unix-like shells. For 'false' to be portable requires a
    header, unfortunately (although Unix-like systems usually say that it
    returns 1 explicitly, because the implementation defines how the values
    returned are treated by the system).

    Chris C
     
    Chris Croughton, Jul 21, 2005
    #13
  14. Chris Croughton <> writes:
    [...]
    > true.c:
    >
    > int main(void) {return 0;}
    >
    > Very useful in Unix-like shells. For 'false' to be portable requires a
    > header, unfortunately (although Unix-like systems usually say that it
    > returns 1 explicitly, because the implementation defines how the values
    > returned are treated by the system).


    <SOMEWHAT_OT>
    I've seen implementations of /bin/false that return a value of 255.
    (Unix treats any non-zero status as false.)

    If it's for Unix only, portability isn't much of a concert; "exit 1;"
    is ok.
    </SOMEWHAT_OT>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Jul 21, 2005
    #14
  15. In article <>,
    Keith Thompson <> wrote:

    ><SOMEWHAT_OT>


    >If it's for Unix only, portability isn't much of a concert; "exit 1;"
    >is ok.


    I would think that "return 1;" or "exit(1);" would be better, at least
    if you're planning to put it in something you're giving to a C compiler.

    ></SOMEWHAT_OT>



    dave
    (regularly uses a system where /bin/false is "exit 1")

    --
    Dave Vandervies
    ome models of the DS9000 use an eleven-bit byte, and ... those eleven bits
    occupy all but one of the vertices of a regular dodecahedron (the twelfth
    vertex is reserved for future expansion). --Eric Sosman in comp.lang.c
     
    Dave Vandervies, Jul 22, 2005
    #15
  16. (Dave Vandervies) writes:
    > In article <>,
    > Keith Thompson <> wrote:
    >
    >><SOMEWHAT_OT>

    >
    >>If it's for Unix only, portability isn't much of a concert; "exit 1;"
    >>is ok.

    >
    > I would think that "return 1;" or "exit(1);" would be better, at least
    > if you're planning to put it in something you're giving to a C compiler.
    >
    >></SOMEWHAT_OT>

    >
    >
    > dave
    > (regularly uses a system where /bin/false is "exit 1")


    Sorry, I forgot to add the

    #define exit exit(1);

    above the "exit 1;".

    (Either than, or I had just been looking at a /bin/false
    implementation that happened to be a Bourne shell script, and I simply
    wasn't paying enough attention to what I was writing -- but that
    hardly seems plausible.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Jul 22, 2005
    #16
  17. CK

    Guest

    Richard Bos wrote:
    > Rob Morris <> wrote:
    >
    > > wrote:
    > > >
    > > > CK wrote:
    > > >
    > > >>This is the World Smallest Program in c.
    > > >
    > > > ???? In what sense, it is worlds smallest? and what does it do?

    > >
    > > It's not the world's smallest, it's the "World Smallest"
    > >
    > > Call it with 2 or more arguments, and it prints out a little text world
    > > map, though I'm not sure how portable it is. I'm sure we've all written
    > > little text-picture-encoded-in-a-string programs, but I found it a
    > > fairly amusing post.

    >
    > But it still isn't the smallest, nor print the smallest. This does:
    >
    > #include <stdio.h>
    > int main(void){puts(".");}
    >
    > C99, of course. And it's a _very_ small world map.
    >
    > Richard


    cc version 4.0.0 compiled this and not only is it a tad smaller, but
    it displays the world's smallest solar system!
    #include <stdio.h>
    int main(){puts(".");}
     
    , Jul 22, 2005
    #17
  18. In article <dbpasg$ggj$>,
    Dave Vandervies <> wrote:
    >
    > ome models of the DS9000 use an eleven-bit byte, and ... those eleven bits
    > occupy all but one of the vertices of a regular dodecahedron (the twelfth
    > vertex is reserved for future expansion). --Eric Sosman in comp.lang.c


    A dodecahedron has 20 vertices, not 12.
    Clearly, Eric meant to say faces.

    http://mathworld.wolfram.com/Dodecahedron.html
    --
    7842++
     
    Anonymous 7843, Jul 22, 2005
    #18
  19. writes:
    > Richard Bos wrote:
    >> Rob Morris <> wrote:
    >>
    >> > wrote:
    >> > >
    >> > > CK wrote:
    >> > >
    >> > >>This is the World Smallest Program in c.
    >> > >
    >> > > ???? In what sense, it is worlds smallest? and what does it do?
    >> >
    >> > It's not the world's smallest, it's the "World Smallest"
    >> >
    >> > Call it with 2 or more arguments, and it prints out a little text world
    >> > map, though I'm not sure how portable it is. I'm sure we've all written
    >> > little text-picture-encoded-in-a-string programs, but I found it a
    >> > fairly amusing post.

    >>
    >> But it still isn't the smallest, nor print the smallest. This does:
    >>
    >> #include <stdio.h>
    >> int main(void){puts(".");}
    >>
    >> C99, of course. And it's a _very_ small world map.
    >>
    >> Richard

    >
    > cc version 4.0.0 compiled this and not only is it a tad smaller, but
    > it displays the world's smallest solar system!
    > #include <stdio.h>
    > int main(){puts(".");}


    The universe before the big bang. Actual size.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Jul 22, 2005
    #19
  20. In article <> Keith Thompson <> writes:
    ....
    > I've seen implementations of /bin/false that return a value of 255.
    > (Unix treats any non-zero status as false.)


    They are mostly shell-scripts. The Solaris script I am looking at returns
    255, and is at version 1.6. I remember a Cray script returning the same
    value and being at version 32.1 or something like that. But on the Linux
    system I am using it is 1 (but it is not a script, but a compiled program,
    and it refused to give the version).
    --
    dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
    home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
     
    Dik T. Winter, Jul 22, 2005
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dev

    Smallest "C" Program !!

    Dev, Feb 8, 2006, in forum: C Programming
    Replies:
    55
    Views:
    3,892
    Keith Thompson
    Feb 13, 2006
  2. World smallest chess program

    , Nov 22, 2006, in forum: C Programming
    Replies:
    63
    Views:
    1,835
    Richard Bos
    Feb 15, 2007
  3. Replies:
    52
    Views:
    3,496
    karthikbalaguru
    Mar 1, 2009
  4. J. D.
    Replies:
    1
    Views:
    130
    J. D.
    Dec 16, 2004
  5. Larry
    Replies:
    27
    Views:
    469
    Michele Dondi
    Jan 25, 2005
Loading...

Share This Page