IOCCC image by Matt Zucker

The International Obfuscated C Code Contest

2001/cheong - Best short program

Computes arbitrary-precision square root

Author:

To build:

    make

Bugs and (Mis)features:

The current status of this entry is:

STATUS: INABIAF - please DO NOT fix

For more detailed information see 2001/cheong in bugs.html.

To use:

    ./cheong digits

Try:

    ./try.sh

Judges’ remarks:

Be sure to give an even number of digits in the argument. Add a leading 0 if needed.

The source code is nice, compact, and self documenting as all good programs should be! :-)

Author’s remarks:

Operation

Compile normally and run with one argument, an integer with 2n digits. Program will return the integer part of its square root (n-digits). For example,

    $ cc -o cheong cheong.c
    $ ./cheong 1234567890
    35136
    $ ./cheong 0200000000000000000000000000
    14142135623730

Deviation from these instructions will cause undefined results. :-)

Portability

This program runs normally on any ANSI C compiler and is ASCII dependent.

Strict compiling gives just one unavoidable warning:

    gcc -ansi -Wall cheong.c
    cheong.c:3: warning: third argument of `main' should probably be `char **'

Obfuscation

The main obfuscation is the algorithm used to calculate square roots, sometimes known as the longhand method. The basic algorithm is itself obfuscated in that it only uses subtraction to calculate square roots. For a detailed explanation, check Google or see Jack Crenshaw’s article at https://web.archive.org/web/20011215124349/http://www.embedded.com/98/9802fe2.htm.

This program uses an even more obscured version which includes the following:

Minor obfuscations:

Challenges for the masses:

Appreciation

Thanks goes out to Bobby Rohde for numerous suggestions on how to shorten the program.

Inventory for 2001/cheong

Primary files

Secondary files


Jump to: top