From ab80ffd699ea297eb48283780876450ed17da236 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 22 Dec 2023 09:56:36 -0800 Subject: [PATCH] Add 2020/kurdyukov4/try.sh + format/typo checks --- 2020/kurdyukov4/README.md | 56 ++++++++++++++++++++++----------------- 2020/kurdyukov4/try.sh | 49 ++++++++++++++++++++++++++++++++++ thanks-for-help.md | 15 +++++++++++ 3 files changed, 95 insertions(+), 25 deletions(-) create mode 100755 2020/kurdyukov4/try.sh diff --git a/2020/kurdyukov4/README.md b/2020/kurdyukov4/README.md index 09e668baa..c69119a08 100644 --- a/2020/kurdyukov4/README.md +++ b/2020/kurdyukov4/README.md @@ -14,14 +14,11 @@ make ### Try: -```sh -./prog Shakespeare.txt 2000 10 1 -./prog Shakespeare.txt 2000 9 1 -./prog Shakespeare.txt 2000 8 1 -# ... Why does it get progressively slower when the context length decreases? +When running this, ask yourself why it gets progressively slower when the +context length decreases: -./prog Eugene_Onegin.txt 2000 10 1 -# For those not knowing Russian, just to see how the UTF-8 characters are handled +```sh +./try.sh ``` > Performance depends on the number of same hashes found. @@ -31,14 +28,18 @@ make ## Judges' remarks: -We were able to [write our own program](rand.c) performing the same trick using the (still -non-standard, for some reason) library function `memmem()`, but that way it -works too fast regardless of the context length, and it's much less fun. +We were able to [write our own program](rand.c) performing the same trick using +the (still non-standard, for some reason) library function `memmem()`, but that +way it works too fast regardless of the context length, and it's much less fun. -> Wow, amazing! Very fast, but there is a drawback to randomness. -> If some string only appears after half the input, the first instance -> of this string will have a 50% chance of occurrence. -> Example: +The author wrote in reply: + +--- + +Wow, amazing! Very fast, but there is a drawback to randomness. +If some string only appears after half the input, the first instance +of this string will have a 50% chance of occurrence. +Example: ``` echo "00000000000000000000 01 02 02 02 02 02 02" > test.txt @@ -51,19 +52,23 @@ echo "00000000000000000000 01 02 02 02 02 02 02" > test.txt > But this will happen very rarely on real data. > -- Author +--- + + Try using the same random seed and varying the context size. BTW: what on Middle-earth is `lámatyávë`? It's Quenya, one of the languages of the Elves in Tolkien's Legendarium. It means sound taste (plural is lámatyáver) -and it refers to phonaesthesia - the pleasure of sound and form of words. It's -discussed in [Morgoth's Ring](https://en.wikipedia.org/wiki/Morgoth%27s_Ring), -volume X of [History of Middle-earth -(HoMe)](https://en.wikipedia.org/wiki/The_History_of_Middle-earth). Now can you -appreciate the award title a bit better? +and it refers to phonaesthesia - in other words, it refers to the pleasure of +sound and form of words. It's discussed in [Morgoth's +Ring](https://en.wikipedia.org/wiki/Morgoth%27s_Ring), volume X of [History of +Middle-earth (HoMe)](https://en.wikipedia.org/wiki/The_History_of_Middle-earth). +Now can you appreciate the award title a bit better? ## Author's remarks: + ### Building: ```sh @@ -73,7 +78,7 @@ cc prog.c -o prog ### Usage: This program generates random text from the provided dictionary using a Markov -chain, outputs to `stdout`. +chain, outputting to `stdout`. ```sh ./prog input.txt 2000 10 12345 @@ -82,19 +87,19 @@ chain, outputs to `stdout`. Parameters are: 1. dictionary filename - Need at least the size of the book, the more the better (1Mb), you can + Need at least the size of the book, the more the better (1Mb); you can concatenate several books into one file. This should be a text file (not - `.doc`/`.pdf`). You can feed with books in `.fb2` format, metadata is + `.doc`/`.pdf`). You can feed it with books in `.fb2` format, metadata is filtered. Whitespace characters are also filtered. For languages other than English, it's better to use ANSI encoding. You can use UTF, but you need to - increase chain length (if one ANSI character is encoded as two UTF bytes, + increase the chain length (if one ANSI character is encoded as two UTF bytes, then multiply chain length by two). 2. bytes to generate (limited to 1Mb) 3. chain length Randomness and performance depend inversely on this parameter and the size - of the dictionary. If you feel that bytes are generated too slowly, then you + of the dictionary. If you feel that the bytes are generated too slowly, then you need to increase the length of the chain. This length means that any part of the output of this size in bytes exists somewhere in the dictionary. @@ -102,7 +107,8 @@ Parameters are: ### Example -You can try this with the inputs provided with [2019/mills](/2019/mills/prog.c) from the IOCCC winners. +You can try this with the inputs provided with +[2019/mills](/2019/mills/README.md) from the IOCCC winners. ```sh diff --git a/2020/kurdyukov4/try.sh b/2020/kurdyukov4/try.sh new file mode 100755 index 000000000..977dbed01 --- /dev/null +++ b/2020/kurdyukov4/try.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2020/kurdyukov4 +# + +# 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 + +read -r -n 1 -p "Press any key to run: ./prog Shakespeare.txt 2000 10 1: " +echo 1>&2 +./prog Shakespeare.txt 2000 10 1 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./prog Shakespeare.txt 2000 9 1: " +echo 1>&2 +./prog Shakespeare.txt 2000 9 1 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./prog Shakespeare.txt 2000 8 1: " +echo 1>&2 +./prog Shakespeare.txt 2000 8 1 + +read -r -n 1 -p "Press any key to run: ./prog Eugene_Onegin.txt 2000 10 1: " +echo 1>&2 +./prog Eugene_Onegin.txt 2000 10 1 + +echo "$ echo "00000000000000000000 01 02 02 02 02 02 02" > test.txt" 1>&2 +echo "00000000000000000000 01 02 02 02 02 02 02" > test.txt +echo 1>&2 +make rand >/dev/null || exit 0 + +read -r -n 1 -p "Press any key to run: ./prog test.txt 1000 2 123: " +echo 1>&2 +./prog test.txt 1000 2 123 +echo 1>&2 +read -r -n 1 -p "Press any key to run: ./rand test.txt 1000 2 123" 1>&2 +echo 1>&2 +./rand test.txt 1000 2 123 + +exit 0 diff --git a/thanks-for-help.md b/thanks-for-help.md index c2b20c6e4..7a2e30da1 100644 --- a/thanks-for-help.md +++ b/thanks-for-help.md @@ -4426,6 +4426,21 @@ README.md. Naturally he's one of the ones who can read text even if it's even more jumbled but we know of others too. +## [2020/kurdyukov4](/2020/kurdyukov4/prog.c) ([README.md](/2020/kurdyukov4/README.md)) + +[Cody](#cody) added the [try.sh](/2020/kurdyukov4/try.sh) script. + +Cody also added from [2019/mills](/2019/mills/README.md) the text file +[Shakespeare.txt](/2020/kurdyukov4/Shakespeare.txt) as we are considering to +have each entry have a tarball with the entry by itself. + +Also, to explain the confusing to most people award, Cody gave a quick +translation of `lámatyávë`, which comes from History of Middle-earth [HoMe], +volume X, Morgoth's Ring, which he also has (and which is part of the 12 volume +set by the late Christopher Tolkien, son and literary executor and heir to +J.R.R. Tolkien). + + ## [2020/tsoj](/2020/tsoj/prog.c) ([README.md](/2020/tsoj/README.md)) [Cody](#cody) added [alternate code](/2020/tsoj/README.md#alternate-code) that will feel