Address 2019 entries
In at least one case some -D flags had to be added to the Makefile. Typo fixes and formatting fixes in some README.md files. For the simply amazing 2019/karns I added a demo.sh which does a cat on the two files (prog.c and maze) and then sleeps for two seconds then runs the program then sleeps for two seconds then resets the terminal (so the colours are messed up). This was added to the README.md file. Several .gitignore files were added. I'm aware that the graphics editing one does not now work under macOS but I'm not sure if this is all versions so I just noted that it doesn't seem to work with recent versions of macOS as I don't have a way to test before Ventura (the current version).
This commit is contained in:
1 parent
7202c81b69
commit
3a4399bf8d
18 files changed
+127
-52
No files matched your search
@@ -1,2 +1,4 @@
|
||||
prog
|
||||
prog.clean
|
||||
correct
|
||||
remarks
|
||||
@@ -399,7 +399,7 @@ prog: prog.c
|
||||
prog.clean: prog.clean.c
|
||||
${CC} ${CSTD} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT} $< -o $@ ${LIBS}
|
||||
|
||||
remarks: remarks.markdown
|
||||
remarks: README.md
|
||||
${CP} $? $@
|
||||
|
||||
correct: newlines remarks 256 check
|
||||
|
||||
@@ -40,7 +40,7 @@ Instead of checking correctness, the check script can simply output the results:
|
||||
out=cat ./check ./prog
|
||||
|
||||
Interestingly, and a spoiler here: MacOS and FreeBSD implement the common utility "correctly".
|
||||
Centos and Ubuntu both share a "flawed" utility that changes output format based upon input redirection or pipeline(!).
|
||||
CentOS and Ubuntu both share a "flawed" utility that changes output format based upon input redirection or pipeline(!).
|
||||
As well, the latter two also behave slightly differently on what they count as whitespace:
|
||||
\a and \b are both counted whitespace(!), even though the relevant man pages on these systems
|
||||
omit these characters from the description.
|
||||
|
||||
Regular → Executable
+1
-1
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
x=$1
|
||||
: ${x:=prog}
|
||||
: ${x:=./prog}
|
||||
|
||||
: ${out:="diff - correct"}
|
||||
|
||||
|
||||
Regular → Executable
File mode changed.
+36
-36
@@ -46,7 +46,7 @@ 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?
|
||||
remove all of the goto jumps in this code?
|
||||
|
||||
## Author's comments:
|
||||
### What is this? <a name="wit"></a>
|
||||
@@ -87,7 +87,7 @@ website](https://www-cs-faculty.stanford.edu/~knuth/fasc5c.ps.gz).
|
||||
|
||||
### Usage
|
||||
|
||||
**`prog LETTERS [N]`**
|
||||
`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
|
||||
@@ -99,73 +99,73 @@ is too long, and 2 if the command-line arguments are missing.
|
||||
|
||||
### Helper scripts
|
||||
|
||||
**`getwords.sh LANGUAGE_CODE`**
|
||||
`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_.
|
||||
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
|
||||
`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,
|
||||
`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>`**
|
||||
_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
|
||||
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`**
|
||||
`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`**.
|
||||
seconds. On the other hand, `prog` can only output series of words
|
||||
with non-repeating characters, unlike `klausler`.
|
||||
|
||||
In contrast to **`prog.alt.c`**, **`prog.c`** does not call
|
||||
**`fflush(stdout)`** after outputting each line, thus running faster.
|
||||
In contrast to `prog.alt.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
|
||||
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
|
||||
`grep .. [FILE]` through `prog` to eliminate the pangrams that
|
||||
contain them.
|
||||
|
||||
According to **`prog`** and **`aspell`**, some languages, e.g. Spanish,
|
||||
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?
|
||||
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:
|
||||
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.
|
||||
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`**.
|
||||
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`.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
<!--
|
||||
|
||||
@@ -4,12 +4,19 @@ Gil Dogon
|
||||
|
||||
|
||||
## Judges' comments:
|
||||
|
||||
## To build:
|
||||
|
||||
make all
|
||||
|
||||
|
||||
### To use:
|
||||
|
||||
make
|
||||
|
||||
./prog < pattern.mc
|
||||
|
||||
NOTE: this entry will likely segfault under macOS if you even get it to compile.
|
||||
|
||||
### Try:
|
||||
|
||||
./prog < glider.mc
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
Darwin
|
||||
prog
|
||||
prog.alt
|
||||
+1
-1
@@ -94,7 +94,7 @@ ARCH=
|
||||
|
||||
# Defines that are needed to compile
|
||||
#
|
||||
CDEFINE=
|
||||
CDEFINE= -Dg=11 -Ds=0 -DV=24 -DW=80
|
||||
#CDEFINE= -DIOCCC
|
||||
|
||||
# Include files that are needed to compile
|
||||
|
||||
+14
-8
@@ -24,9 +24,14 @@ Twitter: @etienne_duble
|
||||
|
||||
./prog /tmp/drawing
|
||||
|
||||
|
||||
NOTE: this entry does not work under at least some versions of macOS.
|
||||
|
||||
|
||||
### Alternate code
|
||||
|
||||
An alternate version of this entry, prog.alt.c, is provided. This alternate code may not work as well on macOS.
|
||||
An alternate version of this entry, prog.alt.c, is provided. This alternate
|
||||
code might not work as well on macOS.
|
||||
|
||||
To compile this alternate version:
|
||||
|
||||
@@ -34,7 +39,8 @@ To compile this alternate version:
|
||||
|
||||
Use `prog.alt` as you would `prog` above.
|
||||
|
||||
### Selected Judges Remarks:
|
||||
|
||||
### Selected Judges' Remarks:
|
||||
|
||||
After starting the program, use the cursor keys, then try some modes, like "p"
|
||||
or "l" (they toggle).
|
||||
@@ -49,7 +55,7 @@ of someone else by just opening the same file!
|
||||
|
||||
### Getting started
|
||||
|
||||
The program can run on Linux, FreeBSD, Mac OS X, and in most terminals.
|
||||
The program can run on Linux, FreeBSD, macOS, and in most terminals.
|
||||
See section 'Limits, Portability' for more info.
|
||||
|
||||
To build, type `make` (assuming gcc) or `make CC=clang`.
|
||||
@@ -112,7 +118,7 @@ reading the source code.
|
||||
### Limits, Portability
|
||||
|
||||
I tested the program on several Linux systems, on FreeBSD 12, and on
|
||||
Mac OS X (mojave).
|
||||
macOS (mojave).
|
||||
|
||||
On Linux, the program uses an OS-specific detail to hide communication
|
||||
artefacts, and avoids the need to remove them on exit.
|
||||
@@ -148,21 +154,21 @@ IMPORTANT NOTES:
|
||||
The file `prog.alt.c` is the one I submitted.
|
||||
|
||||
Judges proposed a small update: the program was using macro `FD_SET` inside an
|
||||
expression, which breaks compilation on Mac OS X. Wrapping this macro into a
|
||||
expression, which breaks compilation on macOS. Wrapping this macro into a
|
||||
function was enough to fix this compilation issue.
|
||||
|
||||
However, that was not enough to make the program work on Mac OS X. If you analyse
|
||||
However, that was not enough to make the program work on macOS. If you analyse
|
||||
the program you will see that it heavily relies on OS resources. And, for this
|
||||
first version of the program, you even needed to increase default `sysctl`
|
||||
parameters to make it work on FreeBSD (this was the purpose of file `check-os.sh`).
|
||||
I tried hard to tune Mac OS X the same, but failed.
|
||||
I tried hard to tune macOS the same, but failed.
|
||||
|
||||
The simple fact Judges proposed this update meant they wish it could work on Mac.
|
||||
And if judges wish something, it **has to** be done. ;)
|
||||
So I refactored a little more the program to reduce OS resources consumption.
|
||||
Or maybe not reduce consumption, but consume them differently...
|
||||
And I obtained `prog.c`. With this version, no need to touch `sysctl` parameters,
|
||||
and it works on Mac OS X too!
|
||||
and it works on macOS too!
|
||||
I must confess it was challenging to remain below the size limit with this little
|
||||
change.
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
prog
|
||||
out.wav
|
||||
@@ -17,6 +17,16 @@ Twitter: @jkarnss
|
||||
|
||||
./prog < README.md
|
||||
|
||||
./prog < prog.c
|
||||
|
||||
./prog < maze
|
||||
|
||||
The last two can be done in a sequence, first showing the respective files at
|
||||
the terminal, like:
|
||||
|
||||
./demo.sh
|
||||
|
||||
|
||||
### Selected Judges Remarks:
|
||||
|
||||
If you typically get lost in mazes, watching this program run might -- or might not, YMMV --
|
||||
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Demo of IOCCC 26 (2019) 'Most in need of whitespace' entry by Joshua Karns.
|
||||
#
|
||||
# Doesn't run the program on README.md as it's longer and slower.
|
||||
#
|
||||
|
||||
# display prog.c to the user
|
||||
echo "$ cat prog.c"
|
||||
cat prog.c
|
||||
sleep 2
|
||||
|
||||
# run the program on itself
|
||||
echo "$ ./prog < prog.c"
|
||||
sleep 2
|
||||
./prog < prog.c
|
||||
sleep 2
|
||||
|
||||
# reset terminal for colours
|
||||
reset
|
||||
|
||||
# display maze
|
||||
echo "$ cat maze"
|
||||
cat maze
|
||||
sleep 2
|
||||
|
||||
# run the program on maze
|
||||
echo "$ ./prog < maze"
|
||||
sleep 2
|
||||
./prog < maze
|
||||
|
||||
sleep 2
|
||||
# reset terminal
|
||||
reset
|
||||
@@ -1 +1,3 @@
|
||||
prog
|
||||
fib
|
||||
fib.c
|
||||
@@ -10,7 +10,7 @@ Twitter: @MisterXopher
|
||||
make
|
||||
|
||||
make cpclean
|
||||
# Let this run for about about an hour and then kill it
|
||||
# Let this run for about about an hour and then kill it:
|
||||
./prog Shakespeare.txt
|
||||
./prog < $(< ls -1tr cp* | tail -1) | head -100
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ Twitter: @timpoiko
|
||||
|
||||
### Try:
|
||||
|
||||
If you don't have a few days, try:
|
||||
If you don't have a few days, try:
|
||||
|
||||
TZ=UTC24 make clobber prog
|
||||
./prog 512 ./prog
|
||||
@@ -45,6 +45,10 @@ or
|
||||
|
||||
clang -O[0123s] -o prog prog.c
|
||||
|
||||
e.g.:
|
||||
|
||||
clang -O1 -o prog prog.c
|
||||
|
||||
### Poster
|
||||
|
||||
You can generate an A3 sized poster by _make docs_. This command creates a pdf file _poikola.pdf_.
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
prog
|
||||
a
|
||||
b
|
||||
c
|
||||
d
|
||||
+5
-1
@@ -5,9 +5,13 @@ Don Yang
|
||||
|
||||
|
||||
## Judges' comments:
|
||||
|
||||
## To build:
|
||||
|
||||
make all
|
||||
|
||||
### To use:
|
||||
|
||||
make
|
||||
|
||||
./prog sample_input.txt a b c d
|
||||
|
||||
|
||||
Reference in new issue
Block a user