Add preview of 1984-2019
The 2020 winners are hinted it, but the source code is not there,
nor are the hints. Someone could look into the HTML and
see what was commented out, but that is not a problem because
WHO won is known and the name of their AWARD is known already.
Moreover a number of the winners have talked about what their
entirs do, so the commented out spoiler text is not a bit problem.
One will find HTML commented out with:
<!-- XXX remove when 2020 is ready
2020 links here
XXX remove when 2020 is ready -->
The "XXX remove when 2020 is ready" string is found at the
start and end comment blocks. Again, soneone could read
what was commented out, but that is OK since most of that
information is known or can be known. The following files
have such HTML comment blocks in them.
./winners.html
./years-spoiler.html
./years.html
In addition, ./all/summary.txt was modified to not
include the 2020 entries for the momemt.
The 2020 winner code AND write-ups are NOT part of this set.
p.s. The all/all.tar.bz2 does not contain the 2020 source code (yet?).
This commit is contained in:
1 parent
28efc67f5d
commit
c0663537cb
1683 files changed
+220064
No files matched your search
@@ -0,0 +1,526 @@
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# 2019 makefile
|
||||
#
|
||||
# This work by Landon Curt Noll, Simon Cooper, and Leonid A. Broukhis
|
||||
# is licensed under:
|
||||
#
|
||||
# Creative Commons Attribution-ShareAlike 3.0 Unported License.
|
||||
#
|
||||
# See: http://creativecommons.org/licenses/by-sa/3.0/
|
||||
|
||||
#############################
|
||||
# shell used by this Makefile
|
||||
#############################
|
||||
#
|
||||
SHELL= /bin/bash
|
||||
|
||||
#######################
|
||||
# common tool locations
|
||||
#######################
|
||||
#
|
||||
A2P= a2p
|
||||
AR= ar
|
||||
ASA= asa
|
||||
AT= at
|
||||
ATQ= atq
|
||||
ATRM= atrm
|
||||
AWK= awk
|
||||
BANNER= banner
|
||||
BASE64= base64
|
||||
BASENAME= basename
|
||||
BATCH= batch
|
||||
BC= bc
|
||||
BINHEX= binhex
|
||||
BISON= bison
|
||||
BUNZIP2= bunzip2
|
||||
BZCAT= bzcat
|
||||
BZCMP= bzcmp
|
||||
BZDIFF= bzdiff
|
||||
BZEGREP= bzegrep
|
||||
BZFGREP= bzfgrep
|
||||
BZGREP= bzgrep
|
||||
BZIP2= bzip2
|
||||
BZLESS= bzless
|
||||
BZMORE= bzmore
|
||||
C2PH= c2ph
|
||||
C89= c89
|
||||
C99= c99
|
||||
CAL= cal
|
||||
CALC= calc
|
||||
CAT= cat
|
||||
CD= cd
|
||||
CHFLAGS= chflags
|
||||
CHGRP= chgrp
|
||||
CHMOD= chmod
|
||||
CKSUM= cksum
|
||||
CLANG= clang
|
||||
CLANG_PLUSPLUS= clang++
|
||||
CLEAR= clear
|
||||
CMP= cmp
|
||||
COL= col
|
||||
COLLDEF= colldef
|
||||
COLRM= colrm
|
||||
COLUMN= column
|
||||
COMPRESS= compress
|
||||
CP= cp
|
||||
CPIO= cpio
|
||||
CPP= cpp
|
||||
CRC32= crc32
|
||||
CSH= csh
|
||||
CSPLIT= csplit
|
||||
CURL= curl
|
||||
CUT= cut
|
||||
C_PLUSPLUS= c++
|
||||
C_PLUSPLUS_FILT= c++filt
|
||||
DATE= date
|
||||
DC= dc
|
||||
DD= dd
|
||||
DF= df
|
||||
DIFF3= diff3
|
||||
DIFF= diff
|
||||
DIG= dig
|
||||
DIRNAME= dirname
|
||||
ED= ed
|
||||
EGREP= egrep
|
||||
ENV= env
|
||||
EQN= eqn
|
||||
ETAGS= etags
|
||||
EXPECT= expect
|
||||
EXPR= expr
|
||||
FALSE= false
|
||||
FGREP= fgrep
|
||||
FILE= file
|
||||
FIND2PERL= find2perl
|
||||
FIND= find
|
||||
FLEX= flex
|
||||
FLEX_PLUSPLUS= flex++
|
||||
FMT= fmt
|
||||
FOLD= fold
|
||||
FS_USAGE= fs_usage
|
||||
FUNZIP= funzip
|
||||
FUSER= fuser
|
||||
GCC= gcc
|
||||
GDIFFMK= gdiffmk
|
||||
GENCAT= gencat
|
||||
GENSTRINGS= genstrings
|
||||
GETOPT= getopt
|
||||
GETOPTS= getopts
|
||||
GNUMAKE= gnumake
|
||||
GREP= grep
|
||||
GROFF= groff
|
||||
GROFFER= groffer
|
||||
GROG= grog
|
||||
GROPS= grops
|
||||
GROTTY= grotty
|
||||
GUNZIP= gunzip
|
||||
GVIM= gvim
|
||||
GZCAT= gzcat
|
||||
GZEXE= gzexe
|
||||
GZIP_PROG= gzip
|
||||
G_PLUSPLUS= g++
|
||||
H2PH= h2ph
|
||||
H2XS= h2xs
|
||||
HASH= hash
|
||||
HEAD= head
|
||||
HOSTNAME_PROG= hostname
|
||||
ICONV= iconv
|
||||
ID= id
|
||||
INDENT= indent
|
||||
INFO= info
|
||||
JOT= jot
|
||||
KILL= kill
|
||||
KSH= ksh
|
||||
LAST= last
|
||||
LD= ld
|
||||
LESSECHO= lessecho
|
||||
LEX= len
|
||||
LINK= link
|
||||
LN= ln
|
||||
LS= ls
|
||||
M4= m4
|
||||
MAKE= make
|
||||
MAN= man
|
||||
MKDIR= mkdir
|
||||
MKFIFo= mkfifo
|
||||
MKTEMP= mktemp
|
||||
MV= mv
|
||||
NANO= nano
|
||||
NASM= nasm
|
||||
NEQN= neqn
|
||||
NICE= nice
|
||||
NL= nl
|
||||
NM= nm
|
||||
NOHUP= nohup
|
||||
NROFF= nroff
|
||||
NSLOOKUP= nslookup
|
||||
OD= od
|
||||
OPENSSL= openssl
|
||||
PASTE= paste
|
||||
PATCH= patch
|
||||
PATHCHK= pathchk
|
||||
PAX= pax
|
||||
PERL= perl
|
||||
PICO= pico
|
||||
PR= pr
|
||||
PRINTENV= printenv
|
||||
PS= ps
|
||||
PTAR= ptar
|
||||
PTARDIFF= ptardiff
|
||||
PTARGREP= ptargrep
|
||||
PWD= pwd
|
||||
PYDOC= pydoc
|
||||
PYTHON= python
|
||||
PYTHONW= pythonw
|
||||
READLINK= readlink
|
||||
RENICE= renice
|
||||
RESET= reset
|
||||
REV= rev
|
||||
RI= ri
|
||||
RM= rm
|
||||
RMDIR= rmdir
|
||||
RSYNC= rsync
|
||||
RUBY= ruby
|
||||
RVIM= rvim
|
||||
SAY= say
|
||||
SCP= scp
|
||||
SCREEN= screen
|
||||
SCRIPT= script
|
||||
SDIFF= sdiff
|
||||
SED= sed
|
||||
SEQ= seq
|
||||
SFTP= sftp
|
||||
SH= sh
|
||||
SHA1= sha1
|
||||
SHA= sha
|
||||
SHAR= shar
|
||||
SHASUM5_18= shasum5.18
|
||||
SHASUM= shasum
|
||||
SIZE= size
|
||||
SLEEP= sleep
|
||||
SORT= sort
|
||||
SSH= ssh
|
||||
STAT= stat
|
||||
STRIP= strip
|
||||
STTY= stty
|
||||
SUM= sum
|
||||
SYNC= sync
|
||||
TABS= tabs
|
||||
TAIL= tail
|
||||
TAR= tar
|
||||
TEE= tee
|
||||
TEST= test
|
||||
TFTP= tftp
|
||||
TIDY= tidy
|
||||
TIME= time
|
||||
TOP= top
|
||||
TOUCH= touch
|
||||
TPUT= tout
|
||||
TPUT= tput
|
||||
TR= tr
|
||||
TROFF= troff
|
||||
TRUE= true
|
||||
TSET= tset
|
||||
TSORT= tsort
|
||||
UL= ul
|
||||
UNAME= uname
|
||||
UNCOMPRESS= uncompress
|
||||
UNEXPAND= unexpand
|
||||
UNIFDEF= unifdef
|
||||
UNIFDEFALL= unifdefall
|
||||
UNIQ= uniq
|
||||
UNITS= units
|
||||
UNLINK= unlink
|
||||
UNZIP= unzip
|
||||
UNZIPSFX= unzipsfx
|
||||
UPTIME= uptime
|
||||
UUDECODE= uudecode
|
||||
UUENCODE= uuencode
|
||||
UUIDGEN= uuidgen
|
||||
VI= vi
|
||||
VIEW= view
|
||||
VIM= vim
|
||||
VIMDIFF= vimdiff
|
||||
W= w
|
||||
WAIT4PATH= wait4path
|
||||
WAIT= wait
|
||||
WC= wc
|
||||
WHAT= what
|
||||
WHATIS= whatis
|
||||
WHICH= which
|
||||
WHO= who
|
||||
WHOAMI= whoami
|
||||
WHOIS= whois
|
||||
WRTIE= write
|
||||
XAR= xar
|
||||
XARGS= xargs
|
||||
XATTR= xattr
|
||||
XXD= xxd
|
||||
YACC= yacc
|
||||
YES= yes
|
||||
ZCAT= zcat
|
||||
ZCMP= zcmp
|
||||
ZDIFF= zdiff
|
||||
ZEGREP= zegrep
|
||||
ZFGREP= zfgrep
|
||||
ZFORCE= zforce
|
||||
ZGREP= zgrep
|
||||
ZIP= zip
|
||||
ZIPCLOAK= zipcloak
|
||||
ZIPGREp= zipgrep
|
||||
ZIPINFo= zipinfo
|
||||
ZIPNOTE= zipnote
|
||||
ZIPSPLIT= zipsplit
|
||||
ZLESS= zless
|
||||
ZMORE= zmore
|
||||
ZNEW= znew
|
||||
ZPRINT= zprint
|
||||
ZSH= zsh
|
||||
|
||||
# Set X11_LIBDIR to the directory where the X11 library resides
|
||||
#
|
||||
#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/X11/include
|
||||
X11_INCDIR= /opt/X11/include
|
||||
|
||||
# Compiler warnings
|
||||
#
|
||||
#CWARN=
|
||||
#CWARN= -Wall
|
||||
#CWARN= -Wall -Wextra
|
||||
CWARN= -Wall -Wextra -pedantic ${CSILENCE}
|
||||
#CWARN= -Wall -Wextra -Weverything
|
||||
#CWARN= -Wall -Wextra -Weverything -pedantic
|
||||
#CWARN= -Wall -Wextra -Weverything -pedantic ${CSILENCE}
|
||||
#CWARN= -W -Wall -Wextra -pedantic ${CSILENCE}
|
||||
|
||||
# Silence warnings that ${CWARN} would normally complain about
|
||||
#
|
||||
#CSILENCE=
|
||||
#CSILENCE= -Wno-implicit-int
|
||||
CSILENCE= -Wno-empty-body -Wno-format-nonliteral -Wno-incompatible-pointer-types-discards-qualifiers -Wno-parentheses -Wno-shorten-64-to-32 -Wno-sign-conversion -Wno-string-plus-int
|
||||
|
||||
# compiler standard
|
||||
#
|
||||
#CSTD=
|
||||
#CSTD= -ansi
|
||||
CSTD= -std=c11
|
||||
|
||||
# compiler bit architecture
|
||||
#
|
||||
# Some entries require 32-bitness:
|
||||
# ARCH= -m32
|
||||
#
|
||||
# Some entries require 64-bitness:
|
||||
# ARCH= -m64
|
||||
#
|
||||
# By default we assume nothing:
|
||||
#
|
||||
ARCH=
|
||||
|
||||
# defines that are needed to compile
|
||||
#
|
||||
CDEFINE=
|
||||
#CDEFINE= -DIOCCC=26
|
||||
|
||||
# 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}
|
||||
|
||||
# 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
|
||||
|
||||
# default flags for ANSI C compilation
|
||||
#
|
||||
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}
|
||||
|
||||
# Libraries needed to build
|
||||
#
|
||||
LIBS=
|
||||
#LIBS= -L ${X11_LIBDIR}
|
||||
|
||||
# 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.
|
||||
#
|
||||
CC= cc
|
||||
#CC=clang
|
||||
MAY_NEED_GCC= gcc
|
||||
|
||||
|
||||
##############################
|
||||
# Special flags for this entry
|
||||
##############################
|
||||
#
|
||||
OBJ= prog.o
|
||||
DATA=
|
||||
TARGET= prog
|
||||
#
|
||||
ALT_OBJ=
|
||||
ALT_TARGET=
|
||||
|
||||
|
||||
#################
|
||||
# build the entry
|
||||
#################
|
||||
#
|
||||
all: ${TARGET} ${DATA}
|
||||
@${TRUE}
|
||||
|
||||
prog: prog.c
|
||||
${CC} ${CFLAGS} $< -o $@ ${LIBS}
|
||||
|
||||
# alternative executable
|
||||
#
|
||||
alt: ${ALT_TARGET}
|
||||
@${TRUE}
|
||||
|
||||
# data files
|
||||
#
|
||||
data: ${DATA}
|
||||
@${TRUE}
|
||||
|
||||
|
||||
###############
|
||||
# utility rules
|
||||
###############
|
||||
#
|
||||
everything: all alt
|
||||
|
||||
clean:
|
||||
${RM} -f ${OBJ} ${ALT_OBJ}
|
||||
|
||||
clobber: clean
|
||||
${RM} -f ${TARGET} ${ALT_TARGET}
|
||||
@-if [ -e sandwich ]; then \
|
||||
${RM} -f sandwich; \
|
||||
echo 'ate sandwich'; \
|
||||
fi
|
||||
|
||||
nuke: clobber
|
||||
@${TRUE}
|
||||
|
||||
dist_clean: nuke
|
||||
@${TRUE}
|
||||
|
||||
install:
|
||||
@echo "Surely you are performing, Dr. May!"
|
||||
@${TRUE}
|
||||
|
||||
# backwards compatibility
|
||||
#
|
||||
build: all
|
||||
@${TRUE}
|
||||
|
||||
|
||||
##################
|
||||
# 133t hacker rulz
|
||||
##################
|
||||
#
|
||||
love:
|
||||
@echo 'not war?'
|
||||
@${TRUE}
|
||||
|
||||
haste:
|
||||
$(MAKE) waste
|
||||
@${TRUE}
|
||||
|
||||
waste:
|
||||
@echo 'haste'
|
||||
@${TRUE}
|
||||
|
||||
make:
|
||||
@echo 'Attend a maker faire'
|
||||
@${TRUE}
|
||||
|
||||
easter_egg:
|
||||
@echo you expected to often mis-understand this $${RANDOM} magic
|
||||
@echo chongo '<was here>' "/\\oo/\\"
|
||||
@echo Eggy
|
||||
|
||||
fabricate fashion form frame manufacture produce: make
|
||||
@${TRUE}
|
||||
|
||||
sandwich:
|
||||
@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
|
||||
@-if [ -r .code_anal ]; then \
|
||||
${RM} -f .code_anal_v6; \
|
||||
else \
|
||||
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:
|
||||
@-if [ -r .code_anal ]; then \
|
||||
ccode_analysis --deep_magic fc6b6af226b7cc598de3d48fc20ed0bd54f7b4f7f0f651a32b9cf8345b2a3b3f --FNV1a_hash_512_bit "prog"; \
|
||||
else \
|
||||
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 --level 391581 --mode 216193 --FNV1a_hash_512_bit "prog"; \
|
||||
else \
|
||||
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: supernova
|
||||
@echo $@ is a dwarf planet
|
||||
@echo dwarf is a type of planet
|
||||
@echo therefore IAU, $@ is a planet
|
||||
|
||||
pluto: supernova
|
||||
${MAKE} charon
|
||||
@echo $@ is a dwarf planet
|
||||
@echo dwarf is a type of planet
|
||||
@echo therefore, $@ is a planet
|
||||
@echo get used to having lots of planets because a $< can ${MAKE} a lot of them
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
set -x
|
||||
./getwords.sh de | tr A-ZÄÖÜ a-zäöü | grep .. | ./prog aäbcdefghijklmnoöpqrsßtuüvwxyz
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
set -x
|
||||
./getwords.sh en | grep .. | ./prog abcdefghijklmnopqrstuvwxyz
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
set -x
|
||||
./getwords.sh fr | ./prog aàâbcdeéèêfghiîjklmnoôpqrstuùûvwxyz\'
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: $0 <language code>"
|
||||
echo "Run (aspell dump dicts) to see the available codes."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
aspell --lang=$1 dump master \
|
||||
| aspell --lang=$1 expand \
|
||||
| tr ' ' '\n' \
|
||||
| sort -u
|
||||
@@ -0,0 +1,191 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta name="GENERATOR" content="mkd2html 2.2.0">
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=utf-8"> <link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="../hint.css">
|
||||
<title>Most alphabetic</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Most alphabetic</h1>
|
||||
|
||||
<p>Marcin Ciura<br>
|
||||
Twitter: @mciura</p>
|
||||
|
||||
<h2>Judges' comments:</h2>
|
||||
|
||||
<h3>To use:</h3>
|
||||
|
||||
<pre><code>make
|
||||
|
||||
./getwords.sh en | grep .. | ./prog aeiouvwxyz
|
||||
</code></pre>
|
||||
|
||||
<h3>Try:</h3>
|
||||
|
||||
<pre><code>./getwords.sh en | grep .. | ./prog aeiouhjklmnvwxyz
|
||||
|
||||
./getwords.sh en | grep .. | ./prog mrjocktvquizphdbagsfewlynx
|
||||
|
||||
./en.sh
|
||||
|
||||
./fr.sh
|
||||
|
||||
./ru.sh
|
||||
</code></pre>
|
||||
|
||||
<h3>Selected Judges Remarks:</h3>
|
||||
|
||||
<p>A few letters, one at a time, with no repeats.
|
||||
How many different ways can this be done?</p>
|
||||
|
||||
<p>While a quick brown fox might jump over the lazy dog,
|
||||
it has too many repeat letters to allow this entry to repeat.
|
||||
It is better that Mr Jock, TV quiz PhD, bags few lynx.</p>
|
||||
|
||||
<p>Speaking of jumping, can you rewrite the code to
|
||||
remote all of the goto jumps in this code?</p>
|
||||
|
||||
<h2>Author’s comments:</h2>
|
||||
|
||||
<h3>What is this? <a name="wit"></a></h3>
|
||||
|
||||
<p>This entry reads from standard input a list of words in any language
|
||||
written with an alphabet and outputs perfect pangrams composed of these
|
||||
words. A perfect pangram is a series of words that contains every letter
|
||||
of the alphabet exactly once.</p>
|
||||
|
||||
<p>Example execution:</p>
|
||||
|
||||
<pre><code>$ grep .. /usr/share/dict/words | ./prog abcdefghijklmnopqrstuvwxyz
|
||||
qualm fjord wiz pyx vs beg kc nth
|
||||
quartz jinx vs fed kc womb glyph
|
||||
quid jamb fez vs pyx kc growl nth
|
||||
quiz fjord pyx vs bag kc mewl nth
|
||||
quiz fjord pyx vs gab kc mewl nth
|
||||
quiz fjord pyx vs gem bawl kc nth
|
||||
quiz fjord pyx vs meg bawl kc nth
|
||||
quiz fjord vex bawl kc gyp ms nth
|
||||
quiz jamb flex vs kc gyp word nth
|
||||
quiz jamb pyx vs kc flog drew nth
|
||||
quiz jamb pyx vs kc frog lewd nth
|
||||
quiz jamb pyx vs kc frog weld nth
|
||||
quiz jamb pyx vs kc golf drew nth
|
||||
quiz jamb pyx vs kc grew fold nth
|
||||
quiz jamb pyx vs kc grow nth fled
|
||||
quiz jamb pyx vs kc growl fed nth
|
||||
</code></pre>
|
||||
|
||||
<p>Rearranging the words into more or less meaningful expressions is the
|
||||
user’s duty.</p>
|
||||
|
||||
<p>This entry implements Algorithm X (<em>Exact cover via dancing links</em>)
|
||||
from Section 7.2.2.1 in fascicle 5C of <em>The Art of Computer
|
||||
Programming</em> by Donald E. Knuth. As of June 2019, you can download an
|
||||
incomplete draft of the fascicle from <a href="https://www-cs-faculty.stanford.edu/~knuth/fasc5c.ps.gz">Knuth’s
|
||||
website</a>.</p>
|
||||
|
||||
<h3>Usage</h3>
|
||||
|
||||
<p><strong><code>prog LETTERS [N]</code></strong>
|
||||
reads allowed words from standard input and writes perfect pangrams
|
||||
with at most <em>N</em> words composed of <em>LETTERS</em> to standard output, one
|
||||
per line. If <em>N</em> is not given, the number of words in the pangrams is
|
||||
unlimited. The characters in <em>LETTERS</em> must not repeat. The length of
|
||||
<em>LETTERS</em> must not exceed 97 characters.</p>
|
||||
|
||||
<p>The exit status is 0 if no error occurred, 1 if the input word list
|
||||
is too long, and 2 if the command-line arguments are missing.</p>
|
||||
|
||||
<h3>Helper scripts</h3>
|
||||
|
||||
<p><strong><code>getwords.sh LANGUAGE_CODE</code></strong>
|
||||
outputs a sorted list of unique words in a given language, one per
|
||||
line. It requires <strong><code>aspell</code></strong> with a dictionary for <em>LANGUAGE_CODE</em>.</p>
|
||||
|
||||
<p><strong><code>wrapprog.py LETTERS [N]</code></strong>
|
||||
works similarly to <strong><code>prog LETTERS [N]</code></strong> except that it merges
|
||||
anagrams before passing them to <strong><code>prog</code></strong> and expands them in
|
||||
<strong><code>prog</code></strong>’s output. This way, it finishes the job faster than
|
||||
<strong><code>prog</code></strong> when there are millions of perfect pangrams. It requires a
|
||||
UTF-8 locale.</p>
|
||||
|
||||
<p><strong><code>de.sh</code></strong>, <strong><code>en.sh</code></strong>, <strong><code>fr.sh</code></strong>, <strong><code>it.sh</code></strong>, <strong><code>pl.sh</code></strong>,
|
||||
and <strong><code>ru.sh</code></strong> output German, English, French, Italian, Polish,
|
||||
and Russian perfect pangrams, respectively. They require a UTF-8
|
||||
locale.</p>
|
||||
|
||||
<h3>Miscellaneous remarks</h3>
|
||||
|
||||
<p>I dare submit this entry to categories <em>algorithms</em>,
|
||||
<em>internationalization</em> (I have not found active use of <strong><code><wchar.h></code></strong>
|
||||
among the programs that won IOCCC in the past), and <em>obscure bugs</em> (see
|
||||
the questions about Linux core dumps below).</p>
|
||||
|
||||
<p>To a casual eye, this entry may look similar to
|
||||
<a href="https://www.ioccc.org/years.html#2005_klausler">2005 klausler</a>.
|
||||
However, <strong><code>prog</code></strong> is internationalized and way faster. On my machine,
|
||||
<strong><code>./klausler abcdefghijklmnopqrstuvwxyz</code></strong> printed only 3,965 perfect
|
||||
pangrams until I killed it after 144 hours running, while the
|
||||
equivalent
|
||||
<strong><code>tr A-Z a-z < /usr/share/dict/words | egrep -v '^[^ais]$' | ./prog abcdefghijklmnopqrstuvwxyz | wc -l</code></strong>
|
||||
finished in 62 minutes, reporting 1,640,569,315 perfect pangrams, and
|
||||
the example from section <a href="#wit">What is this?</a> finished in 1.35
|
||||
seconds. On the other hand, <strong><code>prog</code></strong> can only output series of words
|
||||
with nonrepeating characters, unlike <strong><code>klausler</code></strong>.</p>
|
||||
|
||||
<p>In contrast to <strong><code>prog.orig.c</code></strong>, <strong><code>prog.c</code></strong> does not call
|
||||
<strong><code>fflush(stdout)</code></strong> after outputting each line, thus running faster.
|
||||
I am grateful to Witold Jarnicki for suggesting this change.
|
||||
The original <strong><code>prog</code></strong> finished the example above in 100 minutes
|
||||
instead of 62 minutes.</p>
|
||||
|
||||
<p>If your word list contains meaningless one-letter words, pipe
|
||||
<strong><code>grep .. [FILE]</code></strong> through <strong><code>prog</code></strong> to eliminate the pangrams that
|
||||
contain them.</p>
|
||||
|
||||
<p>According to <strong><code>prog</code></strong> and <strong><code>aspell</code></strong>, some languages, e.g. Spanish,
|
||||
have no perfect pangrams.</p>
|
||||
|
||||
<p>Why does <strong><code>yes | ./prog y</code></strong> hang on Linux? Change <strong><code>static int</code></strong> to
|
||||
<strong><code>int</code></strong> and <strong><code>static wchar_t</code></strong> to <strong><code>wchar_t</code></strong>, and recompile
|
||||
<strong><code>prog</code></strong>. Why does <strong><code>yes | ./prog y</code></strong> dump core now? Change the line
|
||||
<strong><code>#define P 9<<23^1</code></strong> to <strong><code>#define P 9<<23</code></strong> and recompile
|
||||
<strong><code>prog</code></strong>. Why does <strong><code>yes | ./prog y</code></strong> exit gracefully?</p>
|
||||
|
||||
<p>Answer: Nf bs Whar 2019, guhf znavsrfg ohtf va <strong><code>tyvop</code></strong> 2.22–2.29:
|
||||
<a href="https://sourceware.org/bugzilla/show_bug.cgi?id=20568">1</a> naq
|
||||
<a href="https://sourceware.org/bugzilla/show_bug.cgi?id=20632">2</a>.</p>
|
||||
|
||||
<p>The source code uses <strong><code>goto</code></strong> three times. While it could easily get
|
||||
by without <strong><code>goto M</code></strong> and <strong><code>goto H</code></strong>, I challenge the adherents of
|
||||
structured programming to refactor <strong><code>goto T</code></strong>, which jumps back into a
|
||||
nested <strong><code>if</code></strong> block.</p>
|
||||
|
||||
<p>With the supplied <strong><code>Makefile</code></strong>, both <strong><code>gcc</code></strong> and <strong><code>clang</code></strong> compile
|
||||
<strong><code>prog.c</code></strong> without warnings in C11 and C99 mode. For a clean
|
||||
compilation with <strong><code>gcc -std=c90</code></strong>, add <strong><code>-Wno-format</code></strong> to
|
||||
<strong><code>CSILENCE</code></strong> in <strong><code>Makefile</code></strong>.</p>
|
||||
|
||||
<hr />
|
||||
|
||||
<!--
|
||||
(c) Copyright 1984-2019, [Leo Broukhis, Simon Cooper, Landon Curt Noll][judges] - All rights reserved
|
||||
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License][cc].
|
||||
|
||||
[judges]: http://www.ioccc.org/judges.html
|
||||
[cc]: http://creativecommons.org/licenses/by-sa/3.0/
|
||||
-->
|
||||
|
||||
<TABLE><TR>
|
||||
<TD><a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="/png/by-sa-3.0-88x31.png" /></a></TD>
|
||||
<TD><P>© Copyright 1984-2019,
|
||||
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
|
||||
- All rights reserved<BR>
|
||||
This work is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
|
||||
<TD> <!--<a href="https://validator.w3.org/check?uri=referer"><img src="https://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
|
||||
</TR></TABLE>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,164 @@
|
||||
# Most alphabetic
|
||||
|
||||
Marcin Ciura
|
||||
Twitter: @mciura
|
||||
|
||||
|
||||
## Judges' comments:
|
||||
### To use:
|
||||
|
||||
make
|
||||
|
||||
./getwords.sh en | grep .. | ./prog aeiouvwxyz
|
||||
|
||||
### Try:
|
||||
|
||||
./getwords.sh en | grep .. | ./prog aeiouhjklmnvwxyz
|
||||
|
||||
./getwords.sh en | grep .. | ./prog mrjocktvquizphdbagsfewlynx
|
||||
|
||||
./en.sh
|
||||
|
||||
./fr.sh
|
||||
|
||||
./ru.sh
|
||||
|
||||
### Selected Judges Remarks:
|
||||
|
||||
A few letters, one at a time, with no repeats.
|
||||
How many different ways can this be done?
|
||||
|
||||
While a quick brown fox might jump over the lazy dog,
|
||||
it has too many repeat letters to allow this entry to repeat.
|
||||
It is better that Mr Jock, TV quiz PhD, bags few lynx.
|
||||
|
||||
Speaking of jumping, can you rewrite the code to
|
||||
remote all of the goto jumps in this code?
|
||||
|
||||
## Author's comments:
|
||||
### What is this? <a name="wit"></a>
|
||||
|
||||
This entry reads from standard input a list of words in any language
|
||||
written with an alphabet and outputs perfect pangrams composed of these
|
||||
words. A perfect pangram is a series of words that contains every letter
|
||||
of the alphabet exactly once.
|
||||
|
||||
Example execution:
|
||||
|
||||
$ grep .. /usr/share/dict/words | ./prog abcdefghijklmnopqrstuvwxyz
|
||||
qualm fjord wiz pyx vs beg kc nth
|
||||
quartz jinx vs fed kc womb glyph
|
||||
quid jamb fez vs pyx kc growl nth
|
||||
quiz fjord pyx vs bag kc mewl nth
|
||||
quiz fjord pyx vs gab kc mewl nth
|
||||
quiz fjord pyx vs gem bawl kc nth
|
||||
quiz fjord pyx vs meg bawl kc nth
|
||||
quiz fjord vex bawl kc gyp ms nth
|
||||
quiz jamb flex vs kc gyp word nth
|
||||
quiz jamb pyx vs kc flog drew nth
|
||||
quiz jamb pyx vs kc frog lewd nth
|
||||
quiz jamb pyx vs kc frog weld nth
|
||||
quiz jamb pyx vs kc golf drew nth
|
||||
quiz jamb pyx vs kc grew fold nth
|
||||
quiz jamb pyx vs kc grow nth fled
|
||||
quiz jamb pyx vs kc growl fed nth
|
||||
|
||||
Rearranging the words into more or less meaningful expressions is the
|
||||
user's duty.
|
||||
|
||||
This entry implements Algorithm X (_Exact cover via dancing links_)
|
||||
from Section 7.2.2.1 in fascicle 5C of _The Art of Computer
|
||||
Programming_ by Donald E. Knuth. As of June 2019, you can download an
|
||||
incomplete draft of the fascicle from [Knuth's
|
||||
website](https://www-cs-faculty.stanford.edu/~knuth/fasc5c.ps.gz).
|
||||
|
||||
### Usage
|
||||
|
||||
**`prog LETTERS [N]`**
|
||||
reads allowed words from standard input and writes perfect pangrams
|
||||
with at most _N_ words composed of _LETTERS_ to standard output, one
|
||||
per line. If _N_ is not given, the number of words in the pangrams is
|
||||
unlimited. The characters in _LETTERS_ must not repeat. The length of
|
||||
_LETTERS_ must not exceed 97 characters.
|
||||
|
||||
The exit status is 0 if no error occurred, 1 if the input word list
|
||||
is too long, and 2 if the command-line arguments are missing.
|
||||
|
||||
### Helper scripts
|
||||
|
||||
**`getwords.sh LANGUAGE_CODE`**
|
||||
outputs a sorted list of unique words in a given language, one per
|
||||
line. It requires **`aspell`** with a dictionary for _LANGUAGE_CODE_.
|
||||
|
||||
**`wrapprog.py LETTERS [N]`**
|
||||
works similarly to **`prog LETTERS [N]`** except that it merges
|
||||
anagrams before passing them to **`prog`** and expands them in
|
||||
**`prog`**'s output. This way, it finishes the job faster than
|
||||
**`prog`** when there are millions of perfect pangrams. It requires a
|
||||
UTF-8 locale.
|
||||
|
||||
**`de.sh`**, **`en.sh`**, **`fr.sh`**, **`it.sh`**, **`pl.sh`**,
|
||||
and **`ru.sh`** output German, English, French, Italian, Polish,
|
||||
and Russian perfect pangrams, respectively. They require a UTF-8
|
||||
locale.
|
||||
|
||||
### Miscellaneous remarks
|
||||
|
||||
I dare submit this entry to categories _algorithms_,
|
||||
_internationalization_ (I have not found active use of **`<wchar.h>`**
|
||||
among the programs that won IOCCC in the past), and _obscure bugs_ (see
|
||||
the questions about Linux core dumps below).
|
||||
|
||||
To a casual eye, this entry may look similar to
|
||||
[2005 klausler](https://www.ioccc.org/years.html#2005_klausler).
|
||||
However, **`prog`** is internationalized and way faster. On my machine,
|
||||
**`./klausler abcdefghijklmnopqrstuvwxyz`** printed only 3,965 perfect
|
||||
pangrams until I killed it after 144 hours running, while the
|
||||
equivalent
|
||||
**`tr A-Z a-z < /usr/share/dict/words | egrep -v '^[^ais]$' | ./prog abcdefghijklmnopqrstuvwxyz | wc -l`**
|
||||
finished in 62 minutes, reporting 1,640,569,315 perfect pangrams, and
|
||||
the example from section [What is this?](#wit) finished in 1.35
|
||||
seconds. On the other hand, **`prog`** can only output series of words
|
||||
with nonrepeating characters, unlike **`klausler`**.
|
||||
|
||||
In contrast to **`prog.orig.c`**, **`prog.c`** does not call
|
||||
**`fflush(stdout)`** after outputting each line, thus running faster.
|
||||
I am grateful to Witold Jarnicki for suggesting this change.
|
||||
The original **`prog`** finished the example above in 100 minutes
|
||||
instead of 62 minutes.
|
||||
|
||||
If your word list contains meaningless one-letter words, pipe
|
||||
**`grep .. [FILE]`** through **`prog`** to eliminate the pangrams that
|
||||
contain them.
|
||||
|
||||
According to **`prog`** and **`aspell`**, some languages, e.g. Spanish,
|
||||
have no perfect pangrams.
|
||||
|
||||
Why does **`yes | ./prog y`** hang on Linux? Change **`static int`** to
|
||||
**`int`** and **`static wchar_t`** to **`wchar_t`**, and recompile
|
||||
**`prog`**. Why does **`yes | ./prog y`** dump core now? Change the line
|
||||
**`#define P 9<<23^1`** to **`#define P 9<<23`** and recompile
|
||||
**`prog`**. Why does **`yes | ./prog y`** exit gracefully?
|
||||
|
||||
Answer: Nf bs Whar 2019, guhf znavsrfg ohtf va **`tyvop`** 2.22--2.29:
|
||||
[1](https://sourceware.org/bugzilla/show_bug.cgi?id=20568) naq
|
||||
[2](https://sourceware.org/bugzilla/show_bug.cgi?id=20632).
|
||||
|
||||
The source code uses **`goto`** three times. While it could easily get
|
||||
by without **`goto M`** and **`goto H`**, I challenge the adherents of
|
||||
structured programming to refactor **`goto T`**, which jumps back into a
|
||||
nested **`if`** block.
|
||||
|
||||
With the supplied **`Makefile`**, both **`gcc`** and **`clang`** compile
|
||||
**`prog.c`** without warnings in C11 and C99 mode. For a clean
|
||||
compilation with **`gcc -std=c90`**, add **`-Wno-format`** to
|
||||
**`CSILENCE`** in **`Makefile`**.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
<!--
|
||||
(c) Copyright 1984-2019, [Leo Broukhis, Simon Cooper, Landon Curt Noll][judges] - All rights reserved
|
||||
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License][cc].
|
||||
|
||||
[judges]: http://www.ioccc.org/judges.html
|
||||
[cc]: http://creativecommons.org/licenses/by-sa/3.0/
|
||||
-->
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
(>&2 echo "Please be patient. Extracting Italian words")
|
||||
(>&2 echo "from aspell takes a few minutes.")
|
||||
set -x
|
||||
./getwords.sh it | grep .. | ./prog aàbcdeèéfghiìlmnoòpqrstuùvz #jkwxy
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
set -x
|
||||
./getwords.sh pl | egrep -v '^[^aiouwz]$' | ./prog aąbcćdeęfghijklłmnńoóprsśtuwyzźż
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#define P 9<<23^1
|
||||
#define A 1;O-L;L=0<L[o]?L[K][k]=L
|
||||
#define N for(O=l[k];l-O;O=O[k])for(L=O
|
||||
#define G 1+c[C];c[C]-I;I=0<(l=I[o])?
|
||||
#define R(A,M) wcschr(1+M,A)
|
||||
|
||||
static int C[97],d,k[98^P],O,l=1,o[98^P],L,K[98^P],v[97],V[98],c;
|
||||
static void y(){l[V][v]=l[v][V]=l;N-A,L[k][K]=L,++L[o][o],L-1:L[k]);}
|
||||
static void b(){N+A[k],L[k][K]=L[K],--L[o][o],L+1:L[K]);l[V][v]=l[v];l[v][V]=l[V];}
|
||||
static wchar_t s[P],*w=1+s,*p[P],z[99],**q=p,*W=1+s,*Z;
|
||||
int main(int I,char**j){if(l<I){wint_t S;setlocale(LC_CTYPE,"");
|
||||
for(mbstowcs(l+z,l[j],97);l[z];++l)V[l[v]=l+1]=l[K]=l[k]=l;
|
||||
for(v[*V=l-(*v=1)]=L;WEOF-(S=getwchar())&&P>W-s;++W)if(33>(*W=S)){
|
||||
for(*W=L,Z=w;*Z;++Z)if(R(*Z,Z)||!R(*Z,z)){W=w-1;goto M;}
|
||||
for(I=L;I[w];++I)++o[O=R(I[w],z)-z],k[K[l[o+I+1]=O]=k[l[K+I+1]=O[K]]=l+I+1]=O;
|
||||
*q++=w;l[k]=l+I;o[l+=I+1]=p-q;l[K]=l-I;M:w=1+W;}
|
||||
*j="Dictionary too long\n";if(WEOF-S)H:return fputs(*j,stderr),**j/36;
|
||||
d=2[j]?atoi(2[j]):97;while(P){if(I=*v){for(O=P;I;I=I[v])O>I[o]?l=I,O=I[o]:P;
|
||||
b();c[C]=l[k];T:if(l-c[C]){for(I=G b(),I+1:I[K]);if(d>c++)continue;}else y();
|
||||
}else{for(;I-c;++I){for(O=I[C];0>~O[o];++O);printf(!I+" %ls",p[~O[o]]);}
|
||||
putchar(10);}
|
||||
if(!c--)return 0;
|
||||
for(I=-G y(),I-1:I[k]);
|
||||
l=c[C][o];c[C]=c[C][k];goto T;}}
|
||||
*j="Need an argument or two\n";goto H;}
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#define P 9<<23^1
|
||||
#define A 1;O-L;L=0<L[o]?L[K][k]=L
|
||||
#define N for(O=l[k];l-O;O=O[k])for(L=O
|
||||
#define G 1+c[C];c[C]-I;I=0<(l=I[o])?
|
||||
#define R(A,M) wcschr(1+M,A)
|
||||
|
||||
static int C[97],d,k[98^P],O,l=1,o[98^P],L,K[98^P],v[97],V[98],c;
|
||||
static void y(){l[V][v]=l[v][V]=l;N-A,L[k][K]=L,++L[o][o],L-1:L[k]);}
|
||||
static void b(){N+A[k],L[k][K]=L[K],--L[o][o],L+1:L[K]);l[V][v]=l[v];l[v][V]=l[V];}
|
||||
static wchar_t s[P],*w=1+s,*p[P],z[99],**q=p,*W=1+s,*Z;
|
||||
int main(int I,char**j){if(l<I){wint_t S;setlocale(LC_CTYPE,"");
|
||||
for(mbstowcs(l+z,l[j],97);l[z];++l)V[l[v]=l+1]=l[K]=l[k]=l;
|
||||
for(v[*V=l-(*v=1)]=L;WEOF-(S=getwchar())&&P>W-s;++W)if(33>(*W=S)){
|
||||
for(*W=L,Z=w;*Z;++Z)if(R(*Z,Z)||!R(*Z,z)){W=w-1;goto M;}
|
||||
for(I=L;I[w];++I)++o[O=R(I[w],z)-z],k[K[l[o+I+1]=O]=k[l[K+I+1]=O[K]]=l+I+1]=O;
|
||||
*q++=w;l[k]=l+I;o[l+=I+1]=p-q;l[K]=l-I;M:w=1+W;}
|
||||
*j="Dictionary too long\n";if(WEOF-S)H:return fputs(*j,stderr),**j/36;
|
||||
d=2[j]?atoi(2[j]):97;while(P){if(I=*v){for(O=P;I;I=I[v])O>I[o]?l=I,O=I[o]:P;
|
||||
b();c[C]=l[k];T:if(l-c[C]){for(I=G b(),I+1:I[K]);if(d>c++)continue;}else y();
|
||||
}else{for(;I-c;++I){for(O=I[C];0>~O[o];++O);printf(!I+" %ls",p[~O[o]]);}
|
||||
putchar(10);fflush(stdout);}
|
||||
if(!c--)return 0;
|
||||
for(I=-G y(),I-1:I[k]);
|
||||
l=c[C][o];c[C]=c[C][k];goto T;}}
|
||||
*j="Need an argument or two\n";goto H;}
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
set -x
|
||||
./getwords.sh ru | ./prog абвгдеёжзийклмнопрстуфхцчшщъыьэюя
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
"""Reads allowed words and writes perfect pangrams composed of them.
|
||||
|
||||
Merges anagrams before passing them to ./prog and expands them
|
||||
in ./prog's output.
|
||||
"""
|
||||
|
||||
import collections
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Wraps the execution of ./prog"""
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
sys.stderr.write('Usage: {} LETTERS [N]\n'.format(sys.argv[0]))
|
||||
sys.exit(2)
|
||||
anagrams = collections.defaultdict(list)
|
||||
for line in sys.stdin:
|
||||
word = line.strip()
|
||||
anagrams[''.join(sorted(word))].append(word)
|
||||
prog = subprocess.Popen(
|
||||
['./prog'] + sys.argv[1:],
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE)
|
||||
try:
|
||||
for word in anagrams:
|
||||
prog.stdin.write(bytes(word + '\n', 'utf-8'))
|
||||
except BrokenPipeError:
|
||||
sys.exit(1)
|
||||
prog.stdin.close()
|
||||
for anagram in prog.stdout:
|
||||
words = anagram.decode('utf-8').split()
|
||||
print(' '.join('/'.join(anagrams[w]) for w in words))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user