Merge pull request #1652 from xexyl/howe2015-fixes

This commit is contained in:
Landon Curt Noll authored and GitHub committed 2023-12-06 13:10:09 -08:00
commit 6a93653206
12 files changed
+97367 -99

No files matched your search

+39 -45
View File
@@ -4,6 +4,9 @@
make
```
There is an alternate version provided. See [Alternate code](#alternate-code)
below.
## To use:
@@ -17,49 +20,34 @@ make
### Try:
```sh
./prog prog.alt.c prog.c
make test
./prog -d ABXYEFCD.tmp ACDBECFD.tmp
./prog ABXYEFCD.tmp ACDBECFD.tmp
rm -f curds.tmp whey.tmp
cp /usr/share/man/man1/cc.1 curds.tmp
cp /usr/share/man/man1/cc.1 whey.tmp
chmod 666 whey.tmp
make makeholes
./makeholes -n 1000 whey.tmp
./prog curds.tmp whey.tmp
./avgtime.sh 100 ./prog curds.tmp whey.tmp
# Assuming curl(1) installed, grab a really HUGE text file.
curl -L -o war-and-peace.txt http://www.gutenberg.org/ebooks/2600.txt.utf-8
cp war-and-peace.txt nuked.tmp
./makeholes -c'~' -n 1000 nuked.tmp
./prog war-and-peace.txt nuked.tmp
./avgtime.sh 100 ./prog war-and-peace.txt nuked.tmp
./try.sh
```
## Alternate code:
An alternate version of this entry, `prog.alt.c`, is provided.
This alternate code does not use a 64 bit FNV hash.
This alternate version does not use a 64-bit FNV hash. This was the original
entry but was changed to be the alt version.
### Alternate build:
To compile this alternate version:
```sh
make alt
```
### Alternate use:
Use `prog.alt` as you would `prog` above.
## Judges' remarks:
This is the best use of the FNV that we have seen in the IOCCC so far!
The output, when used without -d, is compatible with POSIX diff and
is suitable for use with patch.
The output, when used without `-d`, is compatible with POSIX `diff(1)` and
is suitable for use with `patch(1)`.
We welcome back Canada to the list of nations from where winning
entries have been submitted.
@@ -70,58 +58,64 @@ during a South Park P.T.A. Meeting?
"We must stop dirty (C) language from getting to our children's ears!"
[Blame Canada](https://www.youtube.com/watch?v=bOR38552MJA):
[Blame Canada](https://www.youtube.com/watch?v=bOR38552MJA)
Or should we teach our youth to understand the intricacies of this code?
Ying Tong Iddle I Po! We suggest you read the source for yourself, which
might be easier than the academic papers it was inspired by.
NOTE: Unlike the original entry source, prog.alt.c, prog.c uses a
NOTE: Unlike the original entry source, [prog.alt.c](prog.alt.c),
[prog.c](prog.c) uses a
64 bit FNV hash and fixes a function call warning.
## Author's remarks:
### Features
* "An O(NP) Sequence Comparison Algorithm" by Wu, Manber, Myers, Miller.
* Output compatible with patch(1).
* Output compatible with `patch(1)`.
* Strokes one of the judge's ego (I couldn't email chocolate or curry).
### Description
This is a functioning micro diff tool using an [O(NP) algorithm][Wu+89],
This is a functioning micro `diff(1)` tool using an [O(NP) algorithm][Wu+89],
compared to the older [O(ND) difference algorithm][Mye86] used by some versions
of diff. Its output is based on the default diff(1) output described by POSIX
and [The Open Group Base Specifications][SUSV7]. The output is suitable for use
with patch(1).
of `diff(1)`. Its output is based on the default `diff(1)` output described by POSIX
and [the Open Group Base Specifications][SUSV7]. The output is suitable for use
with `patch(1)`.
The `-d` option simply writes the edit distance between `file1` and `file2`.
The -d option simply writes the edit distance between file1 and file2.
### Observations
The FNV1a hash is a little slow compared to the trivial hash GNU Diff uses. I
downloaded a plain text copy of "War And Peace" from Project Gutenberg, used
``makeholes.c`` to make 1000 random changes, then profiled and timed the program
verses GNU Diff. The bottleneck appears to be in the file I/O and line hashing
with an average +0.05s slower. Using a huge file like "War And Peace" for
testing offsets the diff(1) optimised file I/O.
The FNV1a hash is a little slow compared to the trivial hash [GNU
diff](https://www.gnu.org/software/diffutils/) uses. I downloaded a plain text
copy of "War And Peace" from [Project Gutenberg](https://www.gutenberg.org),
used [makeholes.c](makeholes.c) to make 1000 random changes, then profiled and
timed the program verses GNU `diff(1)`. The bottleneck appears to be in the
file I/O and line hashing with an average +0.05s slower. Using a huge file like
"War And Peace" for testing offsets the `diff(1)` optimised file I/O.
There is no hash collision checking, partly because FNV1a appears to generate
very [few collisions][HshCmp] and an assumption that localised collisions within
a region of edits are highly unlikely.
### Support Files
* ``prog-test.sh``\
Basic test program verifies known test edit distances and patch support.
* [prog-test.sh](prog-test.sh)
Basic test program verifies known test edit distances and `patch(1)` support.
* ``avgtime.sh``
* [avgtime.sh](avgtime.sh)
* ``makeholes.c``\
Random edits (holes) made to a file in-place.
* [makeholes.c](makeholes.c)
Random edits (holes) made to a file in-place.
### References
+24 -5
View File
@@ -1,6 +1,13 @@
#!/usr/bin/env bash
if [[ "$#" -lt 2 ]]; then
echo "usage: $0 <count> <command>" 1>&2
exit 1
fi
COUNT=$1; shift
# ^--^ SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
# shellcheck disable=SC2124
CMD="$@"
N=0
@@ -8,15 +15,27 @@ SYS=0
USER=0
REAL=0
while [ $N -lt $COUNT ]; do
while [[ $N -lt $COUNT ]]; do
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
# 'fixing' this will break the script so we disable it:
# shellcheck disable=SC2086
TIME=$( { /usr/bin/time -l $CMD >/dev/null; } 2>&1 | head -n 1 )
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
# 'fixing' this will break the script so we disable it:
# shellcheck disable=SC2086
REAL="$REAL + $(echo $TIME | cut -d' ' -f1)"
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
# 'fixing' this will break the script so we disable it:
# shellcheck disable=SC2086
USER="$USER + $(echo $TIME | cut -d' ' -f3)"
# ^---^ SC2086 (info): Double quote to prevent globbing and word splitting.
# 'fixing' this will break the script so we disable it:
# shellcheck disable=SC2086
SYS="$SYS + $(echo $TIME | cut -d' ' -f5)"
(( N = $N + 1 ))
((N++))
done
printf 'avg-real\t%.3f\n' $(echo "scale=3; ( $REAL ) / $COUNT" | bc)
printf 'avg-user\t%.3f\n' $(echo "scale=3; ( $USER ) / $COUNT" | bc)
printf 'avg-sys\t%.3f\n' $(echo "scale=3; ( $SYS ) / $COUNT" | bc)
printf 'avg-real\t%.3f\n' "$(echo "scale=3; ( $REAL ) / $COUNT" | bc)"
printf 'avg-user\t%.3f\n' "$(echo "scale=3; ( $USER ) / $COUNT" | bc)"
printf 'avg-sys\t%.3f\n' "$(echo "scale=3; ( $SYS ) / $COUNT" | bc)"
+31041
View File
File diff suppressed because it is too large. Load diff
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 2015/howe
#
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
# this way allows us to have the user specify a different compiler in an easy
# way.
if [[ -z "$CC" ]]; then
CC="cc"
fi
make CC="$CC" all >/dev/null || exit 1
# clear screen after compilation so that only the entry is shown
clear
./prog prog.alt.c prog.c
make test
./prog -d ABXYEFCD.tmp ACDBECFD.tmp
./prog ABXYEFCD.tmp ACDBECFD.tmp
rm -f curds.tmp whey.tmp
cp -f cc.1 curds.tmp
cp -f cc.1 whey.tmp
chmod 666 whey.tmp
make makeholes
./makeholes -n 1000 whey.tmp
./prog curds.tmp whey.tmp
./avgtime.sh 100 ./prog curds.tmp whey.tmp
cp -f war-and-peace.txt nuked.tmp
./makeholes -c'~' -n 1000 nuked.tmp
./prog war-and-peace.txt nuked.tmp
./avgtime.sh 100 ./prog war-and-peace.txt nuked.tmp
File diff suppressed because it is too large. Load diff
+3 -3
View File
@@ -136,14 +136,14 @@ DA=100 # Acceleration due to gravity (scaled by 256).
# Smaller values make you glide slower.
DI=-200 # Impulse velocity of a flap (scaled by 256).
# Make larger if you want an less intense tapping experience!
# Make larger if you want a less intense tapping experience!
DB='"<o^="' # Sprite for player when gliding.
# HINT: Try using various emoji.
# HINT: Try using various emojis.
# NOTE: The string MUST be enclosed inside double quotes.
DF='"<ov="' # Sprite for player when flapping.
# HINT: Try using various emoji.
# HINT: Try using various emojis.
# NOTE: The string MUST be enclosed inside double quotes.
DG='"Tap to Flap!"' # Instruction text.
+32 -15
View File
@@ -24,13 +24,21 @@ Press the up arrow and the down arrow at the right time.
## Judges' remarks:
Did you find that mobile application game a bit frustrating?
Well you can adjust the makefile parameters to make life a
Well you can adjust the Makefile parameters to make life a
bit easier for you:
```sh
make clobber all DW=199999 DW=22 DH=16 DA=50 DI=-150
./try.sh
```
which runs:
```sh
make clobber all DW=199999 DW=22 DH=16 DA=50 DI=-150
./prog
```
From the Makefile:
```
@@ -53,14 +61,14 @@ DA=100 # Acceleration due to gravity (scaled by 256).
# Smaller values make you glide slower.
DI=-200 # Impulse velocity of a flap (scaled by 256).
# Make larger if you want an less intense tapping experience!
# Make larger if you want a less intense tapping experience!
DB='"<o^="' # Sprite for player when gliding.
# HINT: Try using various emoji.
# HINT: Try using various emojis.
# NOTE: The string MUST be enclosed inside double quotes.
DF='"<ov="' # Sprite for player when flapping.
# HINT: Try using various emoji.
# HINT: Try using various emojis.
# NOTE: The string MUST be enclosed inside double quotes.
DG='"Tap to Flap!"' # Instruction text.
@@ -68,6 +76,12 @@ DG='"Tap to Flap!"' # Instruction text.
# NOTE: The string MUST be enclosed inside double quotes.
```
WARNING: if you have good eye-hand coordination and too much time on your hands
you might fall asleep while playing as you probably will never die in this mode.
We only stopped when a reminder came through and we tried to mark it complete at
the same time as playing and we almost managed to survive that. At that point we
already scored over 90.
Enjoy!
TAP!! TAP!! TAP!!
@@ -92,6 +106,7 @@ You can even make the game more challenging -- resize the terminal window to
make the world taller or shorter. You'll never be able to get through the
pipes when they are four times as tall!
### Instructions
The instructions are printed at the start of the game: Tap to Flap!
@@ -99,6 +114,7 @@ The instructions are printed at the start of the game: Tap to Flap!
Hit any key to make your bird fly. Navigate her between the gaps in the pipes.
Your score is shown in the upper left, along with your current high-score.
### Customization options
To customize the gameplay, change any of the following options on the compile
@@ -115,18 +131,18 @@ command line:
* `-DI`: Impulse velocity of a flap (scaled by 256). Make this smaller
if you want an intense tapping experience!
* `-DB`: Sprite for player when gliding.
* `-DF`: Sprite for player when flapping.\
* `-DF`: Sprite for player when flapping.
* `-DG`: Instruction text. Change to your native tongue.
Feel free to try out physics or play field options to make the game more
interesting. Try setting the player sprites to change the game completely --
maybe you can be a fish, or a pig -- the options are limitless! Try using
emoji -- you can be a flying beer mug!
emojis -- you can be a flying beer mug!
Note that since the `curses` library on POSIX doesn't natively support wide
characters (needed for UTF-8 support, which is needed for emoji), you may need
to make some changes to the `Makefile` to get emoji to work on your system.
To help you get started, I've included some example substitutions for emoji
characters (needed for UTF-8 support, which is needed for emojis), you may need
to make some changes to the `Makefile` to get emojis to work on your system.
To help you get started, I've included some example substitutions for emojis
sprites and instruction text; for example, type
```sh
@@ -139,19 +155,20 @@ or
make EMOJI=globe
```
for some examples (the full list of options is in the `Makefile`). Don't
forget to `make clobber` first. If the output doesn't look right, you may need
to link with the "wide" version of `ncurses`. On MacOSX 10.11, it should work
with the current `-lcurses`; on Linux, you might need `-lncursesw`.
for some examples (the full list of options is in the `Makefile`). Don't forget
to `make clobber` first (or use `make -B`). If the output doesn't look right,
you may need to link with the "wide" version of `ncurses`. On MacOSX 10.11, it
should work with the current `-lcurses`; on Linux, you might need `-lncursesw`.
See the `Makefile` to make this change if you need to. Or buy a Mac.
You will also need a UTF-8 compatible terminal and an emoji font installed,
and you will need to have your `LANG` environment variable set to use UTF-8.
Again, if this is too complicated, maybe just go and get that Mac.
### Future additions
Future versions of the game will include monitization via the freemium model
Future versions of the game will include monetization via the freemium model
with micropayments for customization options, play-to-win and of course
live-streamed targeted video advertising.
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 2015/mills1 - make it much easier
#
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
# this way allows us to have the user specify a different compiler in an easy
# way.
if [[ -z "$CC" ]]; then
CC="cc"
fi
# clear screen after compilation so that only the entry is shown
clear
make CC="${CC}" clobber all DW=199999 DW=22 DH=16 DA=50 DI=-150 || exit 1
read -r -n 1 -p "Press any key to play (send EOF to quit game): "
./prog
exit 0
+38 -30
View File
@@ -5,6 +5,17 @@ make
```
### Bugs and (Mis)features:
The current status of this entry is:
```
STATUS: INABIAF - please **DO NOT** fix
```
For more detailed information see [2015 mills2 in bugs.md](/bugs.md#2015-mills2).
## To use:
```sh
@@ -15,16 +26,7 @@ make
### Try:
```sh
printf '000I\236\f\31H\260\240\301\203' > ioccc.Z
./prog ioccc.Z
dd bs=1k count=4096 < /dev/urandom > test1
compress < test1 > test1.Z
time ./prog test1.Z | cmp - test1
dd bs=1k count=4096 < /dev/zero > test2
compress < test2 > test2.Z
time ./prog test2.Z | cmp - test2
./try.sh
```
@@ -32,11 +34,15 @@ time ./prog test2.Z | cmp - test2
Without ASCII art, the source code of this entry would have been exactly 256
bytes. Compared to [1990/jaw](http://ioccc.org/years.html#1990_jaw), it is very
impressive, even taking into account the missing atob functionality. Now we wish
for a compress(1)-like compressor using a similar idea.
impressive, even taking into account the missing `atob` functionality. Now we wish
for a `compress(1)`-like compressor using a similar idea.
Why is the sad smiley on line 12 in that particular place?
```c
c=0) :( O
```
## Author's remarks:
@@ -46,16 +52,17 @@ This program is an implementation of the unix `zcat(1)` command for printing
compressed files that have been created by the `compress(1)` command.
The adaptive [LZW](https://en.wikipedia.org/wiki/Lempel–Ziv–Welch) compression
employed by `compress` usually requires a fairly large amount of memory to
build the decompression tables (in fact, `compress` has a command-line option
to control the size of the decompression tables, since some of the early
systems to which it was ported (*cough*MS-DOS*cough*) did not have enough
memory to use the full 16-bit codes). This version has no large static or
dynamic tables. It is able to decompress 16-bit files using a single function
and a few ints.
employed by `compress(1)` usually requires a fairly large amount of memory to
build the decompression tables (in fact, `compress(1)` has a command-line option
to control the size of the decompression tables, since some of the early systems
to which it was ported
(\*cough\*[MS-DOS](https://computerhistory.org/blog/microsoft-ms-dos-early-source-code/?key=microsoft-ms-dos-early-source-code)\*cough\*)
did not have enough memory to use the full 16-bit codes). This version has no
large static or dynamic tables. It is able to decompress 16-bit files using a
single function and a few `int`s.
To run the program, take an existing compressed file and pass it to the program
on the command line. On the odd chance you don't have `compress` hanging about
on the command line. On the odd chance you don't have `compress(1)` hanging about
on your system, I've provided compressed copies of this year's IOCCC rules
and guidelines files. To print them, just do
@@ -83,11 +90,11 @@ complicated by several issues:
* Codes are at bit offsets within the stream, and must be extracted.
* As codes are added to the dictionary, the code word size grows, so finding
the offset to a particular code word is involved.
* The `compress` encoder reserves a code word that clears the coding tables.
* The `compress(1)` encoder reserves a code word that clears the coding tables.
When this is encountered, the computation of offsets and bit sizes reset.
* The `compress` decoder is designed to always read a block of eight code
words at the same time, so that it need only read N bytes to get eight N-bit
code words. When the "clear" code is encountered, the entire eight-word
* The `compress(1)` decoder is designed to always read a block of eight code
words at the same time, so that it need only read `N` bytes to get eight
`N-bit` code words. When the "clear" code is encountered, the entire eight-word
block is flushed (since the decoder didn't know the word size would change).
The program needs to account for this extra flushing.
* The end of the stream is not explicitly marked; the encoder just pads out
@@ -106,9 +113,9 @@ compressed data, it's likely to crash in an interesting manner.
In particular, it doesn't look at the third byte of the header, which encodes
the maximum code word size and whether "block mode" was used when the encoder
was run. If you use `compress` in its default mode, the maximum word size
was run. If you use `compress(1)` in its default mode, the maximum word size
will be 16 bits and "block mode" will be enabled. You are unlikely to find
any files that don't use "block mode", since all versions of `compress` after
any files that don't use "block mode", since all versions of `compress(1)` after
2.0 (circa 1984) use it by default and have no documented way to disable it.
Reducing the bit depth is still possibly by using the `-b` flag. Modern
systems have no problem with the 200 KB or so needed for 16-bit decoder
@@ -121,10 +128,11 @@ In the event that you don't supply an argument, or that argument doesn't name
a readable file, the program will just silently exit. This is a feature.
The program depends on having a little-endian system. On a big-endian system
you will get a weird big-endian version of `compress`, which might have come to
pass in an alternate universe where the vax on which `compress` was authored
had been big-endian. Luckily for us, it wasn't, and neither are most of the
systems you might want to compile this for.
you will get a weird big-endian version of `compress(1)`, which might have come
to pass in an alternate universe where the
[VAX](https://en.wikipedia.org/wiki/VAX) on which `compress(1)` was authored had
been big-endian. Luckily for us, it wasn't, and neither are most of the systems
you might want to compile this for.
## Copyright and CC BY-SA 4.0 License:
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 2015/mills2
#
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
# this way allows us to have the user specify a different compiler in an easy
# way.
if [[ -z "$CC" ]]; then
CC="cc"
fi
make CC="$CC" all >/dev/null || exit 1
# clear screen after compilation so that only the entry is shown
clear
echo "$ printf '000I\236\f\31H\260\240\301\203' > ioccc.Z" 1>&2
printf '000I\236\f\31H\260\240\301\203' > ioccc.Z
echo 1>&2
echo "$ ./prog ioccc.Z" 1>&2
./prog ioccc.Z
echo 1>&2
echo "$ dd bs=512 count=128 < /dev/urandom > test1" 1>&2
dd bs=512 count=128 < /dev/urandom > test1
echo 1>&2
echo "$ compress < test1 > test1.Z" 1>&2
compress < test1 > test1.Z
echo 1>&2
echo "$ time ./prog test1.Z | cmp - test1" 1>&2
time ./prog test1.Z | cmp - test1
echo 1>&2
echo "$ dd bs=512 count=128 < /dev/zero > test2" 1>&2
dd bs=512 count=128 < /dev/zero > test2
echo 1>&2
echo "$ compress < test2 > test2.Z" 1>&2
compress < test2 > test2.Z
echo 1>&2
echo "$ time ./prog test2.Z | cmp - test2" 1>&2
time ./prog test2.Z | cmp - test2
echo 1>&2
echo "$ ./prog ioccc_guidelines.txt.Z" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./prog ioccc_guidelines.txt.Z | less -EXF
echo 1>&2
echo "$ ./prog ioccc_rules.txt.Z" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./prog ioccc_rules.txt.Z | less -EXF
+11 -1
View File
@@ -3059,7 +3059,17 @@ If you want to try and fix this (mis)feature, you are welcome to try.
# 2015
There are no known bugs and (Mis)features for entries in 2015.
## 2015 mills2
### STATUS: INABIAF - please **DO NOT** fix
### Source code: [2015/mills2/prog.c](2015/mills2/prog.c)
### Information: [2015/mills2/README.md](2015/mills2/README.md)
The program doesn't look at the header of files so if it's passed something hat
is not compressed data it's likely to crash.
The program depends on little endian systems.
# 2016
+24
View File
@@ -3803,6 +3803,30 @@ simply typing `make back_to` or `make mullender`.
(Linux doesn't seem to but macOS does).
## [2015/howe](2015/howe/prog.c) ([README.md](2015/howe/README.md))
[Cody](#cody) added the [try.sh](2015/howe/try.sh) script, downloaded the War
and Peace text file, fixed the [avgtime.sh](2015/howe/avgtime.sh) script (it
resulted in standard input errors in piping to `bc(1)`) and added the
[cc.1](2015/howe/cc.1) man page as not all systems have it (in fact it's
`gcc(1)` from Rocky Linux).
## [2015/mills1](2015/mills1/prog.c) ([README.md](2015/mills1/README.md))
[Cody](#cody) added the [try.sh](2015/mills1/try.sh) script which changes the
parameters to what we had in the judges' remarks to make it easier (he only died
when he tried to mark a reminder complete on the other side of the screen at the
same time and he almost survived that, scoring at that point over 90 - but this
also involves good eye-hand coordination and playing games like this in the
past).
## [2015/mills2](2015/mills2/prog.c) ([README.md](2015/mills2/README.md))
[Cody](#cody) added the [try.sh](2015/mills2/try.sh) script.
## [2015/muth](2015/muth/prog.c) ([README.md](2015/muth/README.md))
[Cody](#cody) added the [try.sh](2015/muth/try.sh) script.