473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

World Smallest Program

CK
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

Nov 15 '05 #1
22 7694
CK wrote:
Hi EveryBody!
This is the World Smallest Program in c.


Obviously not, for at least two reasons.

Nov 15 '05 #2
In article <11**********************@f14g2000cwb.googlegroups .com>, CK
<ch***********@gmail.com> 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 /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Nov 15 '05 #3


Chris Hills wrote:
In article <11**********************@f14g2000cwb.googlegroups .com>, CK
<ch***********@gmail.com> 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(){} ?

Nov 15 '05 #4
Chris Hills <ch***@phaedsys.org> wrote:
In article <11**********************@f14g2000cwb.googlegroups .com>, CK
<ch***********@gmail.com> 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
Nov 15 '05 #5


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

Nov 15 '05 #6


Richard Bos wrote:
Chris Hills <ch***@phaedsys.org> wrote:
In article <11**********************@f14g2000cwb.googlegroups .com>, CK
<ch***********@gmail.com> 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?

Nov 15 '05 #7
no**********@yahoo.com 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
Nov 15 '05 #8
Rob Morris <rm***@cam.spam.ac.uk> wrote:
no**********@yahoo.com 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
Nov 15 '05 #9
In article <42***************@news.xs4all.nl>,
Richard Bos <rl*@hoekstra-uitgeverij.nl> wrote:
Chris Hills <ch***@phaedsys.org> wrote:
In article <11**********************@f14g2000cwb.googlegroups .com>, CK
<ch***********@gmail.com> 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 dj******@csclub.uwaterloo.ca

Writing a C program is one possible way to do it.
--Richard Heathfield answers a poorly disguised homework question in CLC
Nov 15 '05 #10
In article <11**********************@f14g2000cwb.googlegroups .com>,
CK <ch***********@gmail.com> 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++
Nov 15 '05 #11
dj******@csclub.uwaterloo.ca (Dave Vandervies) wrote:
In article <42***************@news.xs4all.nl>,
Richard Bos <rl*@hoekstra-uitgeverij.nl> 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
Nov 15 '05 #12
On Wed, 20 Jul 2005 15:07:45 GMT, Richard Bos
<rl*@hoekstra-uitgeverij.nl> wrote:
dj******@csclub.uwaterloo.ca (Dave Vandervies) wrote:
In article <42***************@news.xs4all.nl>,
Richard Bos <rl*@hoekstra-uitgeverij.nl> 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
Nov 15 '05 #13
Chris Croughton <ch***@keristor.net> 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) ks***@mib.org <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.
Nov 15 '05 #14
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> 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 dj******@csclub.uwaterloo.ca
[S]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
Nov 15 '05 #15
dj******@csclub.uwaterloo.ca (Dave Vandervies) writes:
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> 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) ks***@mib.org <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.
Nov 15 '05 #16
In article <db**********@rumours.uwaterloo.ca>,
Dave Vandervies <dj******@csclub.uwaterloo.ca> wrote:

[S]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++
Nov 15 '05 #17
The universe before the big bang. Actual size.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Nov 15 '05 #18
In article <ln************@nuthaus.mib.org> Keith Thompson <ks***@mib.org> 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/
Nov 15 '05 #19
On Thu, 21 Jul 2005 18:51:12 GMT, Keith Thompson
<ks***@mib.org> wrote:
Chris Croughton <ch***@keristor.net> 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.)


Well, it could return any non-zero value, but none of them are portable
except whatever value EXIT_FAILURE happens to have.
If it's for Unix only, portability isn't much of a concert; "exit 1;"
is ok.
A portable concert is an interesting concept <g>. "exit 1;" gives
compiler errors, though...
</SOMEWHAT_OT>


Chris C
Nov 15 '05 #20
On Fri, 22 Jul 2005 02:43:14 GMT, Dik T. Winter
<Di********@cwi.nl> wrote:
In article <ln************@nuthaus.mib.org> Keith Thompson <ks***@mib.org> 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.


The mind boggles. Did they have a change history?
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).


$ /bin/false --version
false (GNU sh-utils) 2.0.11
Written by no one.

Copyright (C) 2000 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Are you sure you're running the program and not a command in your shell
(bash and zsh both implement it as a command directly, without running
the external program)?

Chris C
Nov 15 '05 #21
In article <sl******************@ccserver.keris.net> ch***@keristor.net writes:
On Fri, 22 Jul 2005 02:43:14 GMT, Dik T. Winter
<Di********@cwi.nl> wrote:

....
> 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.


The mind boggles. Did they have a change history?


I have never seen one.
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).


$ /bin/false --version
false (GNU sh-utils) 2.0.11
Written by no one.

Copyright (C) 2000 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Are you sure you're running the program and not a command in your shell
(bash and zsh both implement it as a command directly, without running
the external program)?


I must have made an error when I tried the various possibilities (and my
shell is ksh ;-)):
false (GNU coreutils) 5.0
Written by Jim Meyering.

Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Apparently it is now written by somebody.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 15 '05 #22
"Dik T. Winter" <Di********@cwi.nl> wrote:
I must have made an error when I tried the various possibilities (and my
shell is ksh ;-)):
false (GNU coreutils) 5.0
Written by Jim Meyering.

Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Apparently it is now written by somebody.


Mr. Meyering's mum will be _so_ proud... :-)

Richard
Nov 15 '05 #23

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

55
by: Dev | last post by:
Hello Folks, I had faced this objective in one of my aptitude exams, that "What could be the smallest "C" program? And, as we know, smallest program means, it should execute single statement,...
63
by: biyubi | last post by:
Hi, a year ago I won the 2005 Best Game categoryof the International Obfuscated C Code Contestwith a chess program. http://www.ioccc.org/whowon2005.html...
8
crystal2005
by: crystal2005 | last post by:
I am writing a program that receive maximum of 25 line of string each has 20 characters maximum. The program will print the smallest and the largest string. However the following program gives me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.