From 5d8e0614382c2fb089939f93cef7201ce3ad4776 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Wed, 29 Nov 2023 08:45:24 -0800 Subject: [PATCH 1/4] Add make test rule to 2012/zeitak + formatting The make test rule runs the new test.sh script which checks the return value of the program run on a variety of new files (and the old incorrect.c which was renamed incorrect.paren.c). The new files include 1984/anonymous.c and 1984/anonymous.alt.c as the author explicitly mentioned that entry. The README.md file has been format/typo checked. --- 2012/zeitak/Makefile | 6 +- 2012/zeitak/README.md | 36 ++-- 2012/zeitak/anonymous.alt.c | 2 + 2012/zeitak/anonymous.c | 2 + 2012/zeitak/incorrect.1.quote.c | 7 + 2012/zeitak/incorrect.3.quotes.c | 7 + 2012/zeitak/incorrect.brace.c | 7 + 2012/zeitak/incorrect.bracket.c | 7 + .../zeitak/{incorrect.c => incorrect.paren.c} | 14 +- 2012/zeitak/incorrect.quote-esc.c | 7 + 2012/zeitak/incorrect.single.quote.c | 7 + 2012/zeitak/incorrect.txt | 1 + 2012/zeitak/test.sh | 161 ++++++++++++++++++ thanks-for-fixes.md | 9 + 14 files changed, 251 insertions(+), 22 deletions(-) create mode 100644 2012/zeitak/anonymous.alt.c create mode 100644 2012/zeitak/anonymous.c create mode 100644 2012/zeitak/incorrect.1.quote.c create mode 100644 2012/zeitak/incorrect.3.quotes.c create mode 100644 2012/zeitak/incorrect.brace.c create mode 100644 2012/zeitak/incorrect.bracket.c rename 2012/zeitak/{incorrect.c => incorrect.paren.c} (92%) create mode 100644 2012/zeitak/incorrect.quote-esc.c create mode 100644 2012/zeitak/incorrect.single.quote.c create mode 100644 2012/zeitak/incorrect.txt create mode 100755 2012/zeitak/test.sh diff --git a/2012/zeitak/Makefile b/2012/zeitak/Makefile index 4ddf0734b..05f9d3081 100644 --- a/2012/zeitak/Makefile +++ b/2012/zeitak/Makefile @@ -113,7 +113,7 @@ ENTRY= zeitak PROG= ${ENTRY} # OBJ= ${PROG}.o -DATA= incorrect.c +DATA= incorrect.paren.c incorrect.brace.c incorrect.bracket.c TARGET= ${PROG} # ALT_OBJ= ${PROG}.alt.o @@ -135,6 +135,10 @@ all: data ${TARGET} ${PROG}: ${PROG}.c ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} +test: test.sh + ./$< || exit 1 + + # alternative executable # alt: data ${ALT_TARGET} diff --git a/2012/zeitak/README.md b/2012/zeitak/README.md index a3f6ffa7e..d9788050b 100644 --- a/2012/zeitak/README.md +++ b/2012/zeitak/README.md @@ -4,6 +4,9 @@ make ``` +There is an alternate version that is slightly deobfuscated. See [alternate +code](#alternate-code) below. + ## To use: @@ -18,8 +21,7 @@ try [incorrect.c](incorrect.c) and the program itself. ### Try: ```sh -./zeitak < zeitak.c -./zeitak < incorrect.c +make test ``` NOTE: it prints an error and exits on the first nesting error so it will not @@ -28,17 +30,19 @@ detect multiple issues! ## Alternate code: -An alternate version of this entry, [zeitak.alt.c](zeitak.alt.c), is provided. -The file [zeitak.alt.c](zeitak.alt.c) provides a version that has been slightly -deobfuscated. You may find reading that file helpful in your attempt -to understand this extremely subtle entry. +This version, [zeitak.alt.c](zeitak.alt.c), is a version that has been slightly +deobfuscated. You may find reading it helpful in your attempt to understand +this extremely subtle entry. -To compile this alternate version: + +### Alternate build: ```sh make alt ``` +### Alternate use: + Use `zeitak.alt` as you would `zeitak` above. @@ -55,8 +59,10 @@ just to understand 18 key characters of this code. ## Author's remarks: + ### Nesting Errors Detector + #### What does it do As you have probably understood by looking at the source\*, this program has @@ -69,7 +75,8 @@ If an error is detected, an error message will be printed. If the problem is a superfluous closing bracket, it will even print a few characters around it's position. -* Make sure you view the source with 4 spaces tab width. +\* Make sure you view the source with 4 spaces tab width. + #### Features @@ -99,7 +106,7 @@ even more limited source, that is: * Without any digits. * Without any character constants. -* Without using functions from headers other than stdio. +* Without using functions from headers other than `stdio`. * Without any control-flow keywords (not even the `?:` operator). * Without any arithmetic or logic operators! @@ -107,7 +114,8 @@ So, what's left? Parenthesis, and lots of them, as looking at the source will reveal immediately. The main obfuscation is building the whole algorithm using only function calls, typecasts, array lookups and pointer operators. -##### Additional obfuscations include: + +#### Additional obfuscations include: * Extensive reuse of identifiers: Macros share names with variables, inner curly braces scopes contain variables with names identical to those in the @@ -117,16 +125,16 @@ only function calls, typecasts, array lookups and pointer operators. * Mostly one-letter identifiers. * Complex recursion: A function might call itself once, twice, or not at all. + #### Compilation/Portability/Running Notes * The program requires `char` to be one byte and pointers to be at least two bytes long. * The program was tested on the following platforms: - -- Ubuntu 9.04 32-bit with GCC -- Windows 7 32-bit with GCC -- Windows 7 32-bit with OpenWatcom + - Ubuntu 9.04 32-bit with GCC + - Windows 7 32-bit with GCC + - Windows 7 32-bit with OpenWatcom ## Copyright and CC BY-SA 4.0 License: diff --git a/2012/zeitak/anonymous.alt.c b/2012/zeitak/anonymous.alt.c new file mode 100644 index 000000000..a8681d1e5 --- /dev/null +++ b/2012/zeitak/anonymous.alt.c @@ -0,0 +1,2 @@ +int i;main(){for(;i["] + +int main() { + int i=40; + printf("); + return 0; +} diff --git a/2012/zeitak/incorrect.3.quotes.c b/2012/zeitak/incorrect.3.quotes.c new file mode 100644 index 000000000..017356404 --- /dev/null +++ b/2012/zeitak/incorrect.3.quotes.c @@ -0,0 +1,7 @@ +#include + +int main() { + int i=40; + printf("""); + return 0; +} diff --git a/2012/zeitak/incorrect.brace.c b/2012/zeitak/incorrect.brace.c new file mode 100644 index 000000000..619c29db6 --- /dev/null +++ b/2012/zeitak/incorrect.brace.c @@ -0,0 +1,7 @@ +#include + +int main() {}} + int i=40; + printf("%c",(char)(i))); + return 0; +} diff --git a/2012/zeitak/incorrect.bracket.c b/2012/zeitak/incorrect.bracket.c new file mode 100644 index 000000000..e35e8e795 --- /dev/null +++ b/2012/zeitak/incorrect.bracket.c @@ -0,0 +1,7 @@ +#include + +int main() ]] }} + int i=40; + printf("%c",(char)(i))); + return 0; +} diff --git a/2012/zeitak/incorrect.c b/2012/zeitak/incorrect.paren.c similarity index 92% rename from 2012/zeitak/incorrect.c rename to 2012/zeitak/incorrect.paren.c index 3fc09c23d..c3f00e123 100644 --- a/2012/zeitak/incorrect.c +++ b/2012/zeitak/incorrect.paren.c @@ -1,7 +1,7 @@ -#include - -int main() { - int i=40; - printf("%c",(char)(i))); - return 0; -} +#include + +int main() { + int i=40; + printf("%c",(char)(i))); + return 0; +} diff --git a/2012/zeitak/incorrect.quote-esc.c b/2012/zeitak/incorrect.quote-esc.c new file mode 100644 index 000000000..cc4274a14 --- /dev/null +++ b/2012/zeitak/incorrect.quote-esc.c @@ -0,0 +1,7 @@ +#include + +int main() { + int i=40; + printf("\""); + return 0; +} diff --git a/2012/zeitak/incorrect.single.quote.c b/2012/zeitak/incorrect.single.quote.c new file mode 100644 index 000000000..53c1ca617 --- /dev/null +++ b/2012/zeitak/incorrect.single.quote.c @@ -0,0 +1,7 @@ +#include + +int main() { + int i=40; + printf('); + return 0; +} diff --git a/2012/zeitak/incorrect.txt b/2012/zeitak/incorrect.txt new file mode 100644 index 000000000..1cc80efa6 --- /dev/null +++ b/2012/zeitak/incorrect.txt @@ -0,0 +1 @@ +" diff --git a/2012/zeitak/test.sh b/2012/zeitak/test.sh new file mode 100755 index 000000000..756ebe262 --- /dev/null +++ b/2012/zeitak/test.sh @@ -0,0 +1,161 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2012/zeitak +# + +# 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 + +# assume no error: set ERROR to 0 +ERROR=0 + +read -r -n 1 -p "Press any key to test zeitak.c for nesting errors: " +echo 1>&2 +./zeitak < zeitak.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 3 ]]; then + echo "Error: did not get exit code 3: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat anonymous.c" 1>&2 +cat anonymous.c +echo 1>&2 +read -r -n 1 -p "Press any key to test anonymous.c for nesting errors: " +echo 1>&2 +./zeitak < anonymous.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 3 ]]; then + echo "Error: did not get exit code 3: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat anonymous.alt.c" 1>&2 +cat anonymous.alt.c +echo 1>&2 +read -r -n 1 -p "Press any key to test anonymous.alt.c for nesting errors: " +echo 1>&2 +./zeitak < anonymous.alt.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 3 ]]; then + echo "Error: did not get exit code 3: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.brace.c" 1>&2 +cat incorrect.brace.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.brace.c: " +echo 1>&2 +./zeitak < incorrect.brace.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.bracket.c" 1>&2 +cat incorrect.bracket.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.bracket.c: " +echo 1>&2 +./zeitak < incorrect.bracket.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.paren.c" 1>&2 +cat incorrect.paren.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.paren.c: " +echo 1>&2 +./zeitak < incorrect.paren.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.quote-esc.c" 1>&2 +cat incorrect.quote-esc.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.quote-esc.c: " +echo 1>&2 +./zeitak < incorrect.quote-esc.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.3.quotes.c" 1>&2 +cat incorrect.3.quotes.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.3.quotes.c: " +echo 1>&2 +./zeitak < incorrect.3.quotes.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.single.quote.c" 1>&2 +cat incorrect.single.quote.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.single.quote.c: " +echo 1>&2 +./zeitak < incorrect.single.quote.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.1.quote.c" 1>&2 +cat incorrect.1.quote.c +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.1.quote.c: " +echo 1>&2 +./zeitak < incorrect.1.quote.c +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +echo "$ cat incorrect.txt" 1>&2 +cat incorrect.txt +echo 1>&2 +read -r -n 1 -p "Press any key to test incorrect.txt: " +echo 1>&2 +./zeitak < incorrect.txt +EXIT_CODE="$?" +if [[ "$EXIT_CODE" -ne 10 ]]; then + echo "Error: did not get exit code 10: $EXIT_CODE" 1>&2 + ERROR=1 +fi +echo 1>&2 + +exit "$ERROR" diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 92075cd96..d09d97b16 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3382,6 +3382,15 @@ We're not sure whether we want to thank Cody or not for this :-) and he's not sure if he wants to be thanked either :-) but we appreciate it nonetheless. +## [2012/zeitak](2012/zeitak/zeitak.c) ([README.md](2012/zeitak/README.md])) + +Cody added the `make test` rule and the [test.sh](2012/zeitak/test.sh) along +with a number of files that will be correctly be flagged as incorrect (including +a text file to show that it's not that it parses C but rather just matching +pairs though that should be obvious) and also some that are correct including +1984/anonymous (as the author explicitly mentioned it). + + # 2013 From a84d3f9d3ffa50d46a659e1254441413abf15091 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:27:46 -0800 Subject: [PATCH 2/4] Add 2012/konno/try.sh + format/typo checks --- 2012/konno/README.md | 18 ++++++++++--- 2012/konno/try.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++ thanks-for-fixes.md | 5 ++++ 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100755 2012/konno/try.sh diff --git a/2012/konno/README.md b/2012/konno/README.md index a77cb2f78..62a809901 100644 --- a/2012/konno/README.md +++ b/2012/konno/README.md @@ -4,6 +4,9 @@ make ``` +There is an unobfuscated version of this entry. See [Alternate +code](#alternate-code) below. + ## To use: @@ -17,7 +20,7 @@ NOTE: N is an integer from 0 to 255. ### Try: ```sh -./konno 30 +./try.sh ``` @@ -26,12 +29,17 @@ NOTE: N is an integer from 0 to 255. An alternate version of this entry, [konno.alt.c](konno.alt.c), is provided. This alternate code is an unobfuscated version of the winning code. -To compile this alternate version: + +### Alternate build: + ```sh make alt ``` + +### Alternate use: + Use `konno.alt` as you would `konno` above. @@ -47,7 +55,9 @@ For extra credit, what are the minimal changes to convert it to ### Remarks -This program outputs [elementary cellular automaton](http://mathworld.wolfram.com/ElementaryCellularAutomaton.html) patterns. +This program outputs [elementary cellular +automaton](http://mathworld.wolfram.com/ElementaryCellularAutomaton.html) +patterns. Try: @@ -61,6 +71,7 @@ Try: There are 256 (from 0 through 255) possible rules. + ### Obfuscation This program uses bit operations. I think @@ -77,6 +88,7 @@ is an interesting operation. This isn't equal to operation. What is the operation doing? + ### Limitation This program assumes that the size of `int` is 4. diff --git a/2012/konno/try.sh b/2012/konno/try.sh new file mode 100755 index 000000000..4ded663b1 --- /dev/null +++ b/2012/konno/try.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2012/konno +# + +# 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 "$ ./konno 30" 1>&2 +./konno 30 +echo 1>&2 + +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +echo "$ ./konno 90" 1>&2 +./konno 90 +echo 1>&2 + +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +echo "$ ./konno 102" 1>&2 +./konno 102 +echo 1>&2 + +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +echo "$ ./konno 109" 1>&2 +./konno 109 +echo 1>&2 + +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +echo "$ ./konno 165" 1>&2 +./konno 165 +echo 1>&2 + +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +echo "$ ./konno 42" 1>&2 +./konno 42 +echo 1>&2 + +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +echo "$ ./konno 37" 1>&2 +./konno 37 +echo 1>&2 + +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +echo "$ ./konno 255" 1>&2 +./konno 255 diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index d09d97b16..14b319b57 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3372,6 +3372,11 @@ The fifth script, [try.sh](2012/kang/try.sh), runs a sequence of commands to show different languages and numbers. +## [2012/konno](2012/konno/konno.c) ([README.md](2012/konno/README.md])) + +Cody added the [try.sh](2012/konno/try.sh) script. + + ## [2012/vik](2012/vik/vik.c) ([README.md](2012/vik/README.md])) Based on the author's description it should be able to get this entry to work From d7e73b4f38b1a2e12b64c1736725e51635efd13b Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:57:56 -0800 Subject: [PATCH 3/4] Format/typo check 2012/kang + update try.sh --- 2012/kang/README.md | 51 ++++++++++++++++++++++++--------------------- 2012/kang/try.sh | 13 +++++++----- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/2012/kang/README.md b/2012/kang/README.md index 9a2cf1777..1b1edee7d 100644 --- a/2012/kang/README.md +++ b/2012/kang/README.md @@ -5,7 +5,7 @@ make ``` There is alternate code which fixes some German at the expense of other German. -See [Alternate code](#alternate-code) below. +See [Alternate code](#alternate-code) below for the (fun) rationale here. ## To use: @@ -35,8 +35,8 @@ This alternate code fixes the program that would throw off those who know German where the sound of 'V' is 'F' and so the program had the letter be 'F'. A problem, however, with changing it is that it breaks other words including in German. Thus there is the alternate version instead which fixes a problem for -Germans that causes other problems for Germans so if you're German you'll just -have to deal with it :-) It is, however, good as you can appreciate the entry +Germans that causes problems for Germans so if you're German you'll just have to +deal with it :-) It is, however, good as you might be able appreciate the entry even more. @@ -107,10 +107,10 @@ It accepts a variety of spelt numbers: * It correctly handles `zero`. * Hyphen does not make a difference: `forty-two` and `forty two` are same. So does period or comma. -* Cases do not make a difference either: `TWO`, `Two`, `two` are same. -* `one` and `a` are interchangeable: `one hundred` and `a hundred` are same. +* Cases do not make a difference either: `TWO`, `Two`, `two` are the same. +* `one` and `a` are interchangeable: `one hundred` and `a hundred` are the same. * `and` is optional: `one hundred twenty-three` and `one hundred and twenty-three` - are same. + are the same. * It supports every non-negative integer less than 1015-1. It uses the small scale (i.e. American): `billion` is 109 and `trillion` is 1012. @@ -121,13 +121,14 @@ It does *not* accept some spelt numbers, which I found mostly irrelevant: * A bare `hundred`, `thousand` etc. do not work. * `one million million` does not work. Get used to `one trillion`! + ### Requirements This program is quite portable, only requiring the following: * The signature `int main(int, int)` should be accepted by the linker. (Original version only). -* `char` should be at least 8 bits long (as dictated by the standard), `int` +* `char` should be at least 1 byte long (as dictated by the standard), `int` should be at least 32 bits long, `long long` should be at least 64 bits long. * Both the compiler and execution environment should use an ASCII-compatible character set and two's complement representation. @@ -136,16 +137,18 @@ This program is quite portable, only requiring the following: [trustingtrust]: http://cm.bell-labs.com/who/ken/trust.html -The design of the program explicitly allows for `EOF` which does not equal to -1 -(it has to be negative per the standard) and both signed and unsigned `char`, -for example. Furthermore it is endian-independent. +The design of the program explicitly allows for `EOF` even if it does not equal +`-1` (it has to be negative per the standard but not necessarily `-1`) and both +`signed char` and `unsigned char`, for example. Furthermore it is +endian-independent. + ### Obfuscations (SPOILERS!) Many obfuscations used are typical for standard IOCCC entries: -* Two arguments from `main` function are reused as normal variables. -* Every conditional has been replaced with `?:` ternary operator and `||` +* Two arguments from `main()` function are reused as normal variables. +* Every conditional has been replaced with the `?:` ternary operator and `||` short-circuiting operator. * It has exactly three nested `for` loops and nothing else. * Common two's complement tricks: `~-a` instead of `a-1`, @@ -161,9 +164,9 @@ Many obfuscations used are typical for standard IOCCC entries: Other obfuscations are more subtle: * The string `"1+DIY/.K430x9G(kC["` is 18 bytes long, but actually 19 bytes - including the final null character are used. + including the final NUL character are used. * It internally represents numbers as hexadecimal. When the input is `two - hundred and three`, it actually writes 0x203 as hexadecimal. + hundred and three`, it actually writes `0x203` as hexadecimal. * Some variables (notably, `n`) have dual uses. * The magic number [42][hhgg] makes an appearance. * It has a long long numb-`main`-er within it! @@ -174,24 +177,24 @@ But the most important obfuscation is the clever construction of lookup table. The program uses 11 different characters required for recognizing 22 lexemes: ``` - zero one tw- th(i)r- fo(u)r- fi- six- - seven- eigh- nin- ten eleven twelve - hundred(s) thousand(s) million(s) billion(s) trillion(s) - a and -teen -ty +zero one tw- th(i)r- fo(u)r- fi- six- +seven- eigh- nin- ten eleven twelve +hundred(s) thousand(s) million(s) billion(s) trillion(s) +a and -teen -ty ``` So that they are internally represented as like: ``` - r n tw- tr- fr- f- s- - sn- g- nn- tn ln twl - nr(s) tsan(s) lln(s) blln(s) trlln(s) - a an -tn -ty +r n tw- tr- fr- f- s- +sn- g- nn- tn ln twl +nr(s) tsan(s) lln(s) blln(s) trlln(s) +a an -tn -ty ``` The stemmer recognizes the longest matching prefix, so every lexeme can be recognized by at most three characters (e.g. `trl` instead of `trlln`). This is -also handy for ignoring plurals. But that would make that the table does not fit +also handy for ignoring plurals. But that would make it so that the table does not fit in the printable byte---112 is already almost 27! The trick is to use octal; three characters (`a`, `b` and `g`) are interpreted @@ -213,7 +216,7 @@ More spoilers can be found at ### Acknowledgement The cleaner (size-optimized) version of this program was originally published -in my website in July 2011. Sun Park and others have reviewed it and let me +in my website in July 2011. Sun Park and others have reviewed it and made me aware of possible improvements. I'd also like to thank Seo Sanghyeon for proof-reading remarks. diff --git a/2012/kang/try.sh b/2012/kang/try.sh index fa08e6771..ce013b131 100755 --- a/2012/kang/try.sh +++ b/2012/kang/try.sh @@ -14,17 +14,20 @@ make CC="$CC" everything >/dev/null || exit 1 # clear screen after compilation so that only the entry is shown clear -echo "$ echo Nineteen hundred and eighty-four | ./kang" +echo "$ echo Nineteen hundred and eighty-four | ./kang" 1>&2 echo Nineteen hundred and eighty-four | ./kang -echo "$ echo uno | ./kang" +echo "$ echo uno | ./kang" 1>&2 echo uno | ./kang -echo "$ echo trois | ./kang" +echo "$ echo trois | ./kang" 1>&2 echo trois | ./kang -echo "$ echo fier | ./kang # notice the issue here, see alternate code instead" +echo "$ echo fier | ./kang # notice the issue here, see alternate code instead" 1>&2 echo fier | ./kang # notice the issue here, see alternate code instead -echo "$ echo \"shest'\" | ./kang" +echo "$ echo \"shest'\" | ./kang" 1>&2 echo "shest'" | ./kang + +echo "$ echo dos | ./kang" 1>&2 +echo dos | ./kang From 47500770345a7bbe927522d49f5707d1553a82d0 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:22:09 -0800 Subject: [PATCH 4/4] Add 2012/vik/try.sh + format/typo checks The try.sh script includes the brainfuck feature that the author implemented. --- 2012/vik/.gitignore | 1 + 2012/vik/README.md | 42 ++++++++++++++---------------- 2012/vik/try.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++ thanks-for-fixes.md | 2 ++ 4 files changed, 85 insertions(+), 23 deletions(-) create mode 100755 2012/vik/try.sh diff --git a/2012/vik/.gitignore b/2012/vik/.gitignore index ab94f510a..94929532f 100644 --- a/2012/vik/.gitignore +++ b/2012/vik/.gitignore @@ -1,3 +1,4 @@ +mmm-chocolate.png chocolate-in-ioccc.png encodedimg.png ioccc-in-chocolate.png diff --git a/2012/vik/README.md b/2012/vik/README.md index e2e3ec7a6..feaae0aad 100644 --- a/2012/vik/README.md +++ b/2012/vik/README.md @@ -6,6 +6,9 @@ make This entry requires [Zlib](https://www.zlib.net). +There is an alternate version which might work for Windows. See [Alternate +code](#alternate-code) section below. + ### Bugs and (Mis)features: @@ -50,40 +53,28 @@ To extract the embedded PNG: ./vik d encodedimg.png > restored.png ``` -There is an alternate version which might work for Windows. See Alternate code -section below. - -The author stated that the program will crash if no argument is passed to the -program or if invalid arguments or images of mismatching sizes or unsupported -pixel formats though we note that your computer might also [halt and catch -fire](https://en.wikipedia.org/wiki/Halt_and_Catch_Fire_(computing)) :-) - -This is supposed to happen. As is written in the -[The Jargon File](http://catb.org/jargon/html/F/feature.html): - -``` -That's not a bug, that's a feature. -``` - ### Try: ```sh -./vik e ioccc.png chocolate.png > chocolate-in-ioccc.png -./vik e chocolate.png ioccc.png > ioccc-in-chocolate.png -./vik d chocolate-in-ioccc.png > restored-chocolate.png -./vik d ioccc-in-chocolate.png > restored-ioccc.png +./try.sh ``` ## Alternate code: -For those few who might use Windows, To compile: +For those few who might use Windows this alternate code might work. + + +### Alternate build: ```sh make alt ``` + +### Alternate use: + Use `vik.alt` as you would `vik` above. @@ -114,6 +105,7 @@ one image into another, the width and height needs to be the same. The program only updates the `IDAT` and `IHDR` chunks of the source image. Any additional chunks are copied into the resulting image. + ### Bonus Extractor: For some reason the chocolate image seems to have some special properties. @@ -146,15 +138,16 @@ or helper methods that can be confusing, I placed all functionality in the gives the benefit that all invocations of the function have the same parameters, `argv` and `argc`. This really helps readability, as a programmer doesn't need to remember several variable or function names. I also tried to reduce the -number of keywords, and the program only has four for-loops followed by a single -return statement. There is a little bit of use of the ternary (`?:`) operator, +number of keywords, and the program only has four `for` loops followed by a single +`return` statement. There is a little bit of use of the ternary (`?:`) operator, but this is really there to keep the program as simple as possible. + ### Portability The program is portable to most platforms that have [zlib](https://www.zlib.net) available. The only system dependency is that the program relies on writing -binary data to stdout. +binary data to `stdout`. By default, Microsoft compilers adds carriage returns to new lines, and to compile the program on this platform, the following line can be added after @@ -165,6 +158,9 @@ correctly: _setmode(_fileno(stdout), 0x8000); ``` +NOTE: this is what the [Alternate code](#alternate-code) does. + + ### Limitations The program doesn't have many error checks so passing in invalid arguments diff --git a/2012/vik/try.sh b/2012/vik/try.sh new file mode 100755 index 000000000..deb29e9fb --- /dev/null +++ b/2012/vik/try.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2012/vik +# + +# 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 embed chocolate in chocolate-in-ioccc.png: " +echo 1>&2 +echo "$ ./vik e chocolate-in-ioccc.png \"Mmm... chocolate.\" > mmm-chocolate.png" 1>&2 +./vik e chocolate-in-ioccc.png "Mmm... chocolate." > mmm-chocolate.png +echo 1>&2 + +read -r -n 1 -p "Press any key to extract chocolate from mmm-chocolate.png: " +echo 1>&2 +echo "$ ./vik d mmm-chocolate.png" 1>&2 +./vik d mmm-chocolate.png +echo 1>&2 + +read -r -n 1 -p "Press any key to embed chocolate.png in ioccc.png: " +echo 1>&2 +echo "$ ./vik e ioccc.png chocolate.png > chocolate-in-ioccc.png" 1>&2 +./vik e ioccc.png chocolate.png > chocolate-in-ioccc.png +echo 1>&2 + +read -r -n 1 -p "Press any key to embed ioccc.png in chocolate.png: " +echo 1>&2 +echo "$ ./vik e chocolate.png ioccc.png > ioccc-in-chocolate.png" +./vik e chocolate.png ioccc.png > ioccc-in-chocolate.png +echo 1>&2 + +read -r -n 1 -p "Press any key to embed a brainfuck program as a text file and decode it: " +echo 1>&2 +echo "$ ./vik e ioccc.png .+[.+] > encodedimg.png" 1>&2 +./vik e ioccc.png .+[.+] > encodedimg.png +echo "$ ./vik b encodedimg.png" 1>&2 +./vik b encodedimg.png +echo 1>&2 + +read -r -n 1 -p "Press any key to extract chocolate from chocolate-in-ioccc.png: " +echo 1>&2 +echo "$ ./vik d chocolate-in-ioccc.png > restored-chocolate.png" 1>&2 +./vik d chocolate-in-ioccc.png > restored-chocolate.png +echo 1>&2 +echo "Make sure to open restored-chocolate.png in your graphics viewer of choice!" 1>&2 + +read -r -n 1 -p "Press any key to extract ioccc from ioccc-in-chocolate.png: " +echo 1>&2 +echo "$ ./vik d ioccc-in-chocolate.png > restored-ioccc.png" 1>&2 +./vik d ioccc-in-chocolate.png > restored-ioccc.png +echo "Now make sure to open restored-ioccc.png in your graphics viewer of choice!" 1>&2 + +exit 0 diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 14b319b57..7d29d9b85 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3386,6 +3386,8 @@ this for the few who might use Windows. We're not sure whether we want to thank Cody or not for this :-) and he's not sure if he wants to be thanked either :-) but we appreciate it nonetheless. +Cody also added the [try.sh](2012/vik/try.sh) script. + ## [2012/zeitak](2012/zeitak/zeitak.c) ([README.md](2012/zeitak/README.md]))