diff --git a/2013/cable2/.gitignore b/2013/cable2/.gitignore index bf9ec9290..bb21f2489 100644 --- a/2013/cable2/.gitignore +++ b/2013/cable2/.gitignore @@ -1,7 +1 @@ -ascii.bmp -bonus.bmp cable2 -hello_world.bmp -mixed_sizes.bmp -multi_color.bmp -typeset.bmp diff --git a/2013/cable2/Makefile b/2013/cable2/Makefile index e94d2dfd5..0ec86b2a2 100644 --- a/2013/cable2/Makefile +++ b/2013/cable2/Makefile @@ -1,99 +1,163 @@ #!/usr/bin/env make # -# 2013 makefile +# IOCCC 2013 winning entry - cable2 + +################################################################################ # -# This work by Landon Curt Noll, Simon Cooper, and Leonid A. Broukhis -# is licensed under: +# Regarding individual entries: +# +# IOCCC winning entry code may not work on your system. Even with standards, +# conditions and build environments change, especially when it comes to more +# extreme code such you might find in an IOCCC winner. Moreover, what was +# allowed and liked in one IOCCC contest may no longer be liked/allowed in +# later IOCCC years. +# +# Corrections on winning author and fixing typos in remarks are VERY WELCOME. +# +# GitHub pull requests are welcome: +# +# If you have a patch that might make running an entry work in modern Unix-like +# environments, please create a GitHub pull request for the IOCCC judges to +# consider. +# +# Suggestions and corrections regarding Makefiles, winning author information, +# fixing typos in remarks, and code patches are welcome via opening a GitHub +# issue or better yet, by creating a GitHub pull request for the IOCCC judges +# to consider. To form a GitHub issue or GitHub pull, please visit: +# +# https://github.com/ioccc-src/winner +# +################################################################################ + +# This work by Landon Curt Noll and Leonid A. Broukhis is licensed under: # # Creative Commons Attribution-ShareAlike 3.0 Unported License. # # See: http://creativecommons.org/licenses/by-sa/3.0/ -################ -# tool locations -################ +############################# +# shell used by this Makefile +############################# # SHELL= bash -CP= cp -CPP= cpp -GUNZIP= gunzip -LD= ld -MAKE= make -RM= rm -SED= sed -TAR= tar -TRUE= true + +####################### +# common tool locations +####################### +# +include ../../var.mk # Set X11_LIBDIR to the directory where the X11 library resides # -X11_LIBDIR= /usr/X11R6/lib +#X11_LIBDIR= /usr/X11R6/lib +#X11_LIBDIR= /usr/X11/lib +X11_LIBDIR= /opt/X11/lib # Set X11_INCLUDEDIR to the directory where the X11 include files reside # -X11_INCDIR= /usr/X11R6/include +#X11_INCDIR= /usr/X11R6/include +#X11_INCDIR= /usr/X11/include +X11_INCDIR= /opt/X11/include -# Compiler warnings +# Common C compiler warnings to silence # -#CWARN= -CWARN= -Wall -Wno-bitwise-op-parentheses -Wno-unsequenced \ - -Wno-incompatible-pointer-types -Wno-shift-op-parentheses \ - -Wno-empty-body -Wno-parentheses -Wno-int-conversion \ - -Wno-implicit-int -#CWARN= -Wall -pedantic +#CSILENCE= +CSILENCE= -Wno-bitwise-op-parentheses -Wno-dollar-in-identifier-extension \ + -Wno-empty-body -Wno-implicit-int -Wno-incompatible-pointer-types \ + -Wno-int-conversion -Wno-newline-eof -Wno-parentheses \ + -Wno-shift-op-parentheses -Wno-unsequenced -# compiler standard +# Common C compiler warning flags +# +#CWARN= ${CSILENCE} +#CWARN= -Wall ${CSILENCE} +#CWARN= -Wall -Wextra ${CSILENCE} +CWARN= -Wall -Wextra -pedantic ${CSILENCE} + +# Compiler standard # #CSTD= #CSTD= -ansi -CSTD= -std=c99 +CSTD= -std=gnu11 -# compiler bit architecture +# Compiler bit architecture # # Some entries require 32-bitness: # ARCH= -m32 # -# Some entries require 64-bitess: +# Some entries require 64-bitness: # ARCH= -m64 # # By default we assume nothing: # ARCH= -# optimization +# Defines that are needed to compile +# +CDEFINE= +#CDEFINE= -DIOCCC + +# Include files that are needed to compile +# +CINCLUDE= +#CINCLUDE= -include stdlib.h +#CINCLUDE= -include stdio.h +#CINCLUDE= -include stdlib.h -include stdio.h +#CINCLUDE= -I ${X11_INCDIR} -I ${X11_INCDIR}/X11 +#CINCLUDE= `${SDL2_CONFIG} --cflags` + +# Optimization # # Most compiles will safely use -O2. Some can use only -O1 or -O. # A few compilers have broken optimizers or this entry make break # under those buggy optimizers and thus you may not want anything. +# Reasonable compilers will allow for -O3. # #OPT= #OPT= -O #OPT= -O1 -OPT= -O2 -#OPT= -O3 +#OPT= -O2 +OPT= -O3 + +# Default flags for ANSI C compilation +# +CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT} # Libraries needed to build # LIBS= +#LIBS= -lm +#LIBS= -L ${X11_LIBDIR} -lX11 +#LIBS= `${SDL2_CONFIG} --libs` -# default flags for ANSI C compilation -# -CFLAGS= ${CWARN} ${CSTD} ${ARCH} ${OPT} - -# ANSI compiler -# -# Set CC to the name of your ANSI compiler. -# -# Some entries seem to need gcc. If you have gcc, set -# both CC and MAY_NEED_GCC to gcc. -# -# If you do not have gcc, set CC to the name of your ANSI compiler, and -# set MAY_NEED_GCC to either ${CC} (and hope for the best) or to just : -# to disable such programs. +# C compiler to use # CC= cc #CC=clang -MAY_NEED_GCC= gcc +#CC=gcc + +# Compiler add-ons or replacements for clang only +# +ifeq ($(CC),clang) +# +CSILENCE+= -Wno-cast-align -Wno-comma -Wno-format-nonliteral \ + -Wno-implicit-int-conversion -Wno-missing-variable-declarations \ + -Wno-poison-system-directories -Wno-sign-conversion -Wno-unreachable-code +# +CWARN+= -Weverything +# +endif + +# Specific add-ons or replacements for gcc only +# +ifeq ($(CC),gcc) +# +#CSILENCE+= +# +#CWARN+= +# +endif ############################## @@ -101,61 +165,85 @@ MAY_NEED_GCC= gcc ############################## # ENTRY= cable2 -DATA= example-images.tbz2 -BUILT_DATA= ascii.bmp bonus.bmp hello_world.bmp mixed_sizes.bmp multi_color.bmp typeset.bmp +PROG= ${ENTRY} +# +OBJ= ${PROG}.o +DATA= ascii.bmp bonus.bmp hello_world.bmp mixed_sizes.bmp multi_color.bmp typeset.bmp +TARGET= ${PROG} +# ALT_OBJ= -ALT_ENTRY= +ALT_TARGET= ################# # build the entry ################# # -all: ${ENTRY} data +all: data ${TARGET} @${TRUE} -${ENTRY}: ${ENTRY}.c +.PHONY: all alt data everything clean clobber install \ + love haste waste maker easter_egg sandwich \ + supernova deep_magic magic charon pluto + +${PROG}: ${PROG}.c ${CC} ${CFLAGS} $< -o $@ ${LIBS} # alternative executable # -alt: ${ALT_ENTRY} +alt: data ${ALT_TARGET} @${TRUE} # data files # data: ${DATA} - @echo extracting sample bmp files - ${TAR} -jxvf ${DATA} + @${TRUE} + +# both all and alt +# +everything: all alt ############### # utility rules ############### # -everything: all alt - clean: - ${RM} -f ${ENTRY}.o ${ALT_OBJ} + ${RM} -f ${OBJ} ${ALT_OBJ} + @-if [ -f indent.c ]; then \ + echo ${RM} -f indent.c; \ + ${RM} -f indent.c; \ + fi clobber: clean - ${RM} -f ${ENTRY} ${ALT_ENTRY} - ${RM} -f ${BUILT_DATA} - -nuke: clobber - @${TRUE} - -dist_clean: nuke - @${TRUE} + ${RM} -f ${TARGET} ${ALT_TARGET} + @-if [ -e sandwich ]; then \ + ${RM} -f sandwich; \ + echo 'ate sandwich'; \ + fi install: - @echo "Surely we are joking Dr. Lehmer!" + @echo "Dr. Spock says that is not logical!" @${TRUE} -# backwards compatibility +# you may be able to misunderstand the source by reading indent.c # -build: all - @${TRUE} +indent.c: ${PROG}.c + @if which "${GINDENT}" >/dev/null 2>&1; then \ + echo ${RM} -f $@; \ + ${RM} -f $@; \ + echo "${GINDENT} < $< > $@"; \ + ${GINDENT} < $< > $@; \ + elif which "${INDENT}" >/dev/null 2>&1; then \ + echo ${RM} -f $@; \ + ${RM} -f $@; \ + echo "${INDENT} < $< > $@"; \ + ${INDENT} < $< > $@; \ + else \ + echo "no intent tool found, ident $< yourself, sorry"; \ + echo "exit 1"; \ + exit 1; \ + fi ################## @@ -174,35 +262,69 @@ waste: @echo 'haste' @${TRUE} +maker: + @echo 'Participate in a maker faire' + @${TRUE} + easter_egg: - @echo you expected to mis-understand this $${RANDOM} magic - @echo chongo '' "/\\oo/\\" - @echo Readers shall not be disallowed from being unable to not partly misunderstand this partocular final echo. + @echo "you expected to often misunderstand this $${RANDOM} magic" + @echo "chongo '' /\\oo/\\" + @echo "Eggy" + +sandwich: easter_egg + @if [ `id -u` -eq 0 ]; then \ + echo 'Okay.'; \ + echo "$${RANDOM}`date +%s`$${RANDOM}" > $@; \ + else \ + echo 'What? Make it yourself.'; \ + exit 1; \ + fi # Understand the history of the Homebrew Computer Club # as well as the West Coast Computer Faire and # you might be confused different. :-) # -supernova: nuke +supernova: sandwich @-if [ -r .code_anal ]; then \ - ${RM} -f .code_anal_v4; \ + ${RM} -f .code_anal_v6; \ else \ - echo "We are not expected to understand that"; \ + echo "planet deniers, like some members of the IAU, are so cute when they try to defend their logic"; \ fi + @echo "A $@ helps ${MAKE} the elements that help form planets" @${TRUE} -deep_magic: +deep_magic: supernova @-if [ -r .code_anal ]; then \ - ccode_analysis --deep_magic 2ed3582ec5c094a093fea2a6bcb9f19439892873c9cc45ed1ceaafe08b7d52e1b2c7cd524be3b0b2 --FNV1a_hash 512-bit "${ENTRY}"; \ + ccode_analysis --deep_magic 7889066cdbdf09b0408021754586e895be641cc9be29e7eafd3ca65359541f17 \ + --FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \ else \ - echo "Park different"; \ + echo "Wrong! Do it again!"; \ + sleep 2; \ + echo "Wrong! Do it again!"; \ + sleep 2; \ + echo "Wrong! Do it again!"; \ fi @${TRUE} magic: deep_magic @-if [ -r .code_anal ]; then \ - ccode_analysis --mode 391581 --level 216193 --FNV1a_hash 512-bit "${ENTRY}"; \ + ccode_analysis --level 20003 --mode 5717175 --FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \ else \ - echo "These aren't the primes you're looking for Paul Erdos!"; \ + echo "If you don't eat yer meat, you can't have any pudding!"; \ + echo "How can you have any pudding if you don't eat yer meat?!"; \ fi @${TRUE} + +# The IOCCC resident astronomer states +# +charon: magic + @echo "$@ is a dwarf planet" + @echo "dwarf is a type of planet" + @echo "therefore IAU, $@ is a planet" + +pluto: charon + ${MAKE} charon + @echo "$@ is a dwarf planet" + @echo "dwarf is a type of planet" + @echo "therefore, $@ is a planet" + @echo "having lots of planets is good feature because supernovae can help ${MAKE} a lot of them" diff --git a/2013/cable2/README.md b/2013/cable2/README.md index 8b00f2bf0..8573a15e9 100644 --- a/2013/cable2/README.md +++ b/2013/cable2/README.md @@ -1,114 +1,118 @@ # Best of show -Adrian Cable - + Adrian Cable + +# To build: -## Judges' comments: -### To build: - - make cable2 +```sh +make +``` ### To run: - ./cable2 file.bmp [color] +```sh +./cable2 file.bmp [color] +``` ### Try: -Extract example-images.tbz2: - - make data - Here is an OCR example that shows all 94 supported ASCII characters: - ./cable2 ascii.bmp +```sh +./cable2 ascii.bmp +``` Here is an example of colored ASCII: - ./cable2 multi_color.bmp color +```sh +./cable2 multi_color.bmp color +``` Here is an example using different character sizes and different positions in the same file: - ./cable2 mixed_sizes.bmp +```sh +./cable2 mixed_sizes.bmp +``` How about about hand-written C code: - ./cable2 hello_world.bmp | gcc -xc -o hello - - ./hello +```sh +./cable2 hello_world.bmp | gcc -xc -o hello - +./hello +``` Sometimes typeset text will work, if the typeset has characters that are enough to the supported handwritten shapes. For example, Menlo, 160 pt: - ./cable2 typeset.bmp +```sh +./cable2 typeset.bmp +``` And as an added IOCCC bonus: :-) - ./cable2 bonus.bmp +```sh +./cable2 bonus.bmp +``` -### Selected Judges Remarks: +## Judges' comments: We can confirm that this is the first time the IOCCC has been used to peer-review a new research. We had quite a bit of fun with a sharpie and a scanner. ## Author's comments: -OCR - Obfuscated Character Recognition of Handwritten Text -========================================================== - -This entry takes a BMP image file of hand-drawn (mouse-drawn?) text, specified as the first command-line parameter, and converts it to an ASCII text document. Magic! - -BMP files created by most paint programs should work. The author recommends Paint.NET. - -Features --------- - -- Every printable ASCII character is recognized (94 characters plus space), plus a special bonus character. -- Input images can be any size (limited only by memory), containing any number of lines of text. -- BMP is really a mess of different formats, but the program supports most of them from Windows 3.1 and later. -- Hand-drawn characters in the input image can be variably spaced and positioned and be of any width or height, but the bigger the better for accurate recognition (300 pixels tall or more is recommended). Characters must be drawn with a stroke width of around 9 pixels, and separated from adjacent characters. (In Paint.NET a brush of width 9 works well, with anti-aliasing turned off.) -- You can use any colors you like for the text and background, even different colors for different text characters. -- If "color" is specified as the second command line parameter, the program's output will also be in color, on ANSI/VTxxx terminals. - -Why is this entry obfuscated/interesting? ------------------------------------------ - -- The source is presented as a beautiful moonlit scene, in which a quick brown fox jumps over a lazy dog. Far too often in software development is aesthetic nuance lost in the name of serious-sounding conventions like "GNU style", but not here. -- Newcomers to C find it hard to learn all those different ways to control flow: for, while, if, do, goto, continue, break and heaven knows what else! So, in this program we only use for, so absolute beginners can get into the code straight away. -- To teach newcomers all the important features of C, we demonstrate the importance of the liberal use of short circuits, sequence points, the ternary operator, using x^y or x-y instead of x!=y, using ~x in place of x!=-1 for conciseness, mixing x[y] and y[x] for variety, educational #define's, and so on. -- main is the most useful function in all of C - so it is a mystery to the author why most programs use it only once. Here we use it over and over for maximum benefit. -- The number 42 is featured in the source to provide an answer to the judges' deeper questions. -- How are character colors converted from RGB in the input image to ANSI escape sequences? Clue: the weird macro P does the interesting part of it, but how? -- The program prints a string when the bonus character is detected. How does it do this? Clue: the string to print is defined in the macro $, but how can a string defined in that way ever get printed? - -Other notes ------------ - -- The novel character recognition algorithm used has not been previously published and was developed by the author specifically for the contest. Should this entry win the IOCCC, it will be the first time (to the author's knowledge) that the IOCCC has been used for peer review/publication of original research. -- OCR in general is a hard problem. Here, we only recognise one possible form for each character. You can see what the supported character shapes look like by looking at the examples in ascii.bmp. If you copy the shape of the character forms you find in there, recognition accuracy should be very good (95%+). A more "useful" version would extend the character stroke table to support multiple different commonly-used forms for each character. -- Despite being the largest possible IOCCC entry at 4096 bytes, it is also probably the smallest general-purpose OCR program ever written (including the character stroke data), maybe by several orders of magnitude. -- The author used an interesting compression algorithm (suggested by Gareth McCaughan - thank you!) to squeeze the character stroke table (containing around 2000 strokes for the whole ASCII character set) into a string constant of just 472 characters. - -Bugs/features -------------- - -- The width of input images must be a multiple of 4. -- Input images can be 8-bit grayscale, 24-bit color or 32-bit color only. 8-bit color and 16-bit color are not supported. If you use the "color" command-line feature, do not use a grayscale input file! -- Normal Windows BMP files are stored "upside-down", i.e. the bottom line in the image is written first. Some (old) graphics programs actually write BMP files "top-to-bottom" and the program does not support such files. -- Using antialiased brush strokes to draw your letters is fine, however, antialiasing interferes with color detection in "color" mode. -- Only runs on little endian machines (since the BMP format is little endian, and endianness conversion would make the source too large for IOCCC rule 2). - -Compiler warnings ------------------ - -clang warns about unused expression results, missing type specifiers, and incompatible pointer conversions - all just a fun consequence of the obfuscations. --------------------------------------------------------------------------------- - diff --git a/2013/cable2/ascii.bmp b/2013/cable2/ascii.bmp new file mode 100644 index 000000000..cedebe775 Binary files /dev/null and b/2013/cable2/ascii.bmp differ diff --git a/2013/cable2/bonus.bmp b/2013/cable2/bonus.bmp new file mode 100644 index 000000000..0820badc0 Binary files /dev/null and b/2013/cable2/bonus.bmp differ diff --git a/2013/cable2/example-images.tbz2 b/2013/cable2/example-images.tbz2 deleted file mode 100644 index c67d5e28e..000000000 Binary files a/2013/cable2/example-images.tbz2 and /dev/null differ diff --git a/2013/cable2/hello_world.bmp b/2013/cable2/hello_world.bmp new file mode 100644 index 000000000..4df6c7a27 Binary files /dev/null and b/2013/cable2/hello_world.bmp differ diff --git a/2013/cable2/mixed_sizes.bmp b/2013/cable2/mixed_sizes.bmp new file mode 100644 index 000000000..2949ae7b1 Binary files /dev/null and b/2013/cable2/mixed_sizes.bmp differ diff --git a/2013/cable2/multi_color.bmp b/2013/cable2/multi_color.bmp new file mode 100644 index 000000000..cd52a871c Binary files /dev/null and b/2013/cable2/multi_color.bmp differ diff --git a/2013/cable2/typeset.bmp b/2013/cable2/typeset.bmp new file mode 100644 index 000000000..f5871bb7e Binary files /dev/null and b/2013/cable2/typeset.bmp differ