From a19cb214c156b543c00d94d36e8fe004e9387710 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:16:54 -0800 Subject: [PATCH] Add 2001/herrmann2/try.sh + format/typo fixes The try.sh script has quite a lot of complicated commands and steps which makes it much more useful than some others. The .gitignore was updated for this script. The README.md file has been format and typo checked. --- 2001/herrmann2/.gitignore | 4 +++ 2001/herrmann2/README.md | 46 ++++-------------------- 2001/herrmann2/try.sh | 74 +++++++++++++++++++++++++++++++++++++++ thanks-for-fixes.md | 5 ++- 4 files changed, 87 insertions(+), 42 deletions(-) create mode 100755 2001/herrmann2/try.sh diff --git a/2001/herrmann2/.gitignore b/2001/herrmann2/.gitignore index 007a0870a..b70087acc 100644 --- a/2001/herrmann2/.gitignore +++ b/2001/herrmann2/.gitignore @@ -1,3 +1,7 @@ herrmann2 herrmann2.orig prog.orig +ioccc.out +ioccc.out2 +cup.out +cup.out2 diff --git a/2001/herrmann2/README.md b/2001/herrmann2/README.md index 48d2c12c5..6292ed35f 100644 --- a/2001/herrmann2/README.md +++ b/2001/herrmann2/README.md @@ -15,14 +15,9 @@ make ### Try: ```sh -./herrmann2 < herrmann2.ioccc -./herrmann2 < herrmann2.cup +./try.sh ``` -Try running each command a few times and notice the different output. Can you -figure out why each is different? - - If you use vi(m) you can see a pattern in [herrmann2.cup](herrmann2.cup) and [herrmann2.ioccc][(herrmann2.ioccc]) by say: @@ -51,34 +46,6 @@ and in [herrmann2.ioccc](herrmann2.ioccc) try: /n ``` -### Also try: - -```sh -./herrmann2 \ -'char*d,A[9876];e;b;*ad,a,c; tw,ndr,T; wri; ;*h; _,ar ;on;'\ -' ;l ;i(V)man,n {-!har ; =Aadre(0,&e,o||n -- +,o4,=9,l=b=8,'\ -'!( te-*Aim)|(0~l),srand (l),,!A,d=,b))&&+((A + te-A(&(*)=+ +95>'\ -'e?(*& c_*r=5,r+e-r +_:2-19<-+?|(d==d),!n ?*d| *( (char**)+V+), ('\ -' +0,*d-7 ) -r+8)c:7:+++7+! r: and%9- 85! ()-(r+o):(+w,_+ A*(=er'\ -'i+(o)+b)),!write,(=_((-b+*h)(1,A+b,!!((((-+, a >T^l,( o-95=+))w?'\ -'++ &&r:b<<2+a +w) ((!main(n*n,V) , +-) ),l)),w= +T-->o +o+;{ &!'\ -'a;}return _+= ' < herrmann2.ioccc > herrmann2.orig.c && \ -diff herrmann2.alt.c herrmann2.orig.c && echo "output matches with original code" -``` - - -## Alternate code: - -If you wish to use the original version that does not work for all platforms -(and will not even compile with some versions of clang), you can make use of the -[herrmann2.alt.c](herrmann2.alt.c) by running: - -```sh -make alt -``` - -Use `herrmann2.alt` as you would `herrmann2` above. - ## Judges' remarks: @@ -90,8 +57,8 @@ if you concentrate on your focus you will find illumination! You probably know those "magic eye" 3D pictures - pictures looking like random noise, but when you look "through" the paper, you -either get a three dimensional picture or a head-ache. With this -program, you can create your own 3D pictures in ascii art. And +either get a three dimensional picture or a headache. With this +program, you can create your own 3D pictures in ASCII art. And yes, the program itself is such a 3D picture. @@ -176,6 +143,7 @@ program length. big as possible, but small enough to be viewed without problems on normal-sized terminals. + ### Why this program should win - The layout is of a completely new kind. And it describes what @@ -203,12 +171,12 @@ stuff doing mostly nothing.) obfuscated: It's (almost) only one big expression, with deep nesting of `()` and `?:`, and full of unnecessary operations which do not really help making it readable. And it contains a lot of -"magic numbers". (My favourite is the "7" in line 15 (each +"magic numbers". (My favourite is the `7` in line 15 (each one). Which is the other digit I could have put there instead, and what other changes to the program would have been necessary? Without violating the constraints of course.) -- The fact that the main loop of the program calls `main` +- The fact that the main loop of the program calls `main()` recursively is nothing new. New however is that this program only needs a logarithmic recursion depth! (Find out how this works.) @@ -225,7 +193,7 @@ and let the result inspire you. ;-) - I fear that gcc is the only compiler for which this program works. Due to the severe restrictions, I was forced to use -declarations of int variables, functions and parameters without +declarations of `int` variables, functions and parameters without specifying their type. The biggest problem was to put `int main(int c, char ** v){` into the program. After some time, I became convinced that this is impossible. Finally, at least I diff --git a/2001/herrmann2/try.sh b/2001/herrmann2/try.sh new file mode 100755 index 000000000..b5067120b --- /dev/null +++ b/2001/herrmann2/try.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2001/herrmann2 +# + +# 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 + +# we need to remove some files for later +rm -f ioccc.out ioccc.out2 cup.out cup.out2 + +echo "$ ./herrmann2 \ +'char*d,A[9876];e;b;*ad,a,c; tw,ndr,T; wri; ;*h; _,ar ;on;'\ +' ;l ;i(V)man,n {-!har ; =Aadre(0,&e,o||n -- +,o4,=9,l=b=8,'\ +'!( te-*Aim)|(0~l),srand (l),,!A,d=,b))&&+((A + te-A(&(*)=+ +95>'\ +'e?(*& c_*r=5,r+e-r +_:2-19<-+?|(d==d),!n ?*d| *( (char**)+V+), ('\ +' +0,*d-7 ) -r+8)c:7:+++7+! r: and%9- 85! ()-(r+o):(+w,_+ A*(=er'\ +'i+(o)+b)),!write,(=_((-b+*h)(1,A+b,!!((((-+, a >T^l,( o-95=+))w?'\ +'++ &&r:b<<2+a +w) ((!main(n*n,V) , +-) ),l)),w= +T-->o +o+;{ &!'\ +'a;}return _+= ' < herrmann2.ioccc > herrmann2.orig.c && \ +echo && diff -s herrmann2.alt.c herrmann2.orig.c" 1>&2 + +./herrmann2 \ +'char*d,A[9876];e;b;*ad,a,c; tw,ndr,T; wri; ;*h; _,ar ;on;'\ +' ;l ;i(V)man,n {-!har ; =Aadre(0,&e,o||n -- +,o4,=9,l=b=8,'\ +'!( te-*Aim)|(0~l),srand (l),,!A,d=,b))&&+((A + te-A(&(*)=+ +95>'\ +'e?(*& c_*r=5,r+e-r +_:2-19<-+?|(d==d),!n ?*d| *( (char**)+V+), ('\ +' +0,*d-7 ) -r+8)c:7:+++7+! r: and%9- 85! ()-(r+o):(+w,_+ A*(=er'\ +'i+(o)+b)),!write,(=_((-b+*h)(1,A+b,!!((((-+, a >T^l,( o-95=+))w?'\ +'++ &&r:b<<2+a +w) ((!main(n*n,V) , +-) ),l)),w= +T-->o +o+;{ &!'\ +'a;}return _+= ' < herrmann2.ioccc > herrmann2.orig.c && \ +echo && diff -s herrmann2.alt.c herrmann2.orig.c + +echo 1>&2 +echo "./herrmann2 "234 84 045 5 6765 7487 65190 84 656 254 12 43931 818 0 6542 \ +341 45 567 76967 7244 606 976567 895 81898 095 68678 1843 4650547 \ +565980691 389 04974" < herrmann2.ioccc" 1>&2 + +./herrmann2 "234 84 045 5 6765 7487 65190 84 656 254 12 43931 818 0 6542 \ +341 45 567 76967 7244 606 976567 895 81898 095 68678 1843 4650547 \ +565980691 389 04974" < herrmann2.ioccc +echo 1>&2 + +rm -f ioccc.out ioccc.out2 +read -r -n 1 -p "Press any key to test the output a couple times on herrmann2.ioccc: " +echo "$ ./herrmann2 < herrmann2.ioccc" 1>&2 +./herrmann2 < herrmann2.ioccc | tee ioccc.out +sleep 2 +echo "$ ./herrmann2 < herrmann2.ioccc" 1>&2 +./herrmann2 < herrmann2.ioccc | tee ioccc.out2 +echo "$ diff ioccc.out ioccc.out2" 1>&2 +diff ioccc.out ioccc.out2 +rm -f ioccc.out ioccc.out2 +echo 1>&2 + +read -r -n 1 -p "Press any key to test the output a couple times on herrmann2.cup: " +echo "$ ./herrmann2 < herrmann2.cup" 1>&2 +./herrmann2 < herrmann2.cup | tee cup.out +sleep 2 +echo "$ ./herrmann2 < herrmann2.cup" 1>&2 +./herrmann2 < herrmann2.cup | tee cup.out2 +echo "$ diff cup.out cup.out2" 1>&2 +diff cup.out cup.out2 + +rm -f cup.out cup.out2 diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 51e19d7ce..0f173a5b3 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -2579,9 +2579,8 @@ compile with clang by changing the args of main to be `int` and `char **`, respectively, and changing specific references to the `argv` arg, casting to `long` (was `int` but the 64-bit fix requires `long`) which was its old type. -The original file, used for demonstration purposes, as well as if you want to -see if your system works with the original code, is the alternate version. See -the README.md for details. +Cody also added the [try.sh](2001/herrmann2/try.sh) script which might be more +useful than any other place as the command to try is quite long with C code. For some reason the original code was missing (presumingly because it had been added to `.gitignore` by accident) but Cody restored it from the archive.