From c7c274e5e0cc7724ff23395b9e1134012cef59a9 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Tue, 28 Nov 2023 09:56:18 -0800 Subject: [PATCH] Add 2011/hamaji/try.sh, .nono files + formatting The .nono files are more data files, some based on the authors' remarks and two from a website they linked to. The try.sh script runs the program on those files, others that were already provided and if perl is installed it verifies that the perl script will generate the same output as the entry being fed dragon.nono. Format/typo check README.md file. This should complete the review of 2011/hamaji. --- 2011/hamaji/README.md | 93 ++++++++++++++------------- 2011/hamaji/conway-game-of-life.nono | 8 +++ 2011/hamaji/multi-solutions.nono | 5 ++ 2011/hamaji/no-solution.nono | 3 + 2011/hamaji/plus.nono | 13 ++++ 2011/hamaji/smiley.nono | 31 +++++++++ 2011/hamaji/try.sh | 95 ++++++++++++++++++++++++++++ thanks-for-fixes.md | 12 ++++ 8 files changed, 215 insertions(+), 45 deletions(-) create mode 100644 2011/hamaji/conway-game-of-life.nono create mode 100644 2011/hamaji/multi-solutions.nono create mode 100644 2011/hamaji/no-solution.nono create mode 100644 2011/hamaji/plus.nono create mode 100644 2011/hamaji/smiley.nono create mode 100755 2011/hamaji/try.sh diff --git a/2011/hamaji/README.md b/2011/hamaji/README.md index f62d83d6d..12bd5e410 100644 --- a/2011/hamaji/README.md +++ b/2011/hamaji/README.md @@ -15,22 +15,23 @@ make ### Try: ```sh -./hamaji < dragon.nono -./hamaji < random.nono -./hamaji < soccer.nono -./hamaji < codegolf.nono -./hamaji < face.nono -./hamaji < penguin.nono -./hamaji < samurai.nono +./try.sh +``` + +If you have perl installed you should be able to reproduce +[dragon.nono](dragon.nono) like: + +```sh +perl c2nono.pl hamaji.c | ./hamaji ``` ## Judges' remarks: -This program solves "Nonogram", which also known as "Paint by Numbers": -. +This program solves [Nonograms](http://en.wikipedia.org/wiki/Nonogram) which is +also known as "Paint by Numbers". -This entry roar as the Year of the Dragon: A year considered +This entry roars as the Year of the Dragon: A year considered some to be good luck. Well it was certainly true that the IOCCC was lucky to get such a fine submission! @@ -39,8 +40,7 @@ paint by C. Try your hand at solving a few of the other `.nono` files and then compare your solution with this program! NOTE: NONOGRAM (r) is a registered Trademark and is used with permission. See - for more -information. + for more information. ## Author's remarks: @@ -52,26 +52,26 @@ For example, for a simple problem which shows a glider of [Conway's Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life): ``` - 1 - . - 112 + 1 + . + 112 - 1 X - 1 X - 3 XXX +1 X +1 X +3 XXX ``` the input should be ``` - 1 - 1 - 3 - - - 1 - 1.1 - 2 +1 +1 +3 +- +1 +1.1 +2 ``` The width and the height of an input puzzle should be less than or @@ -82,9 +82,9 @@ This means the problem is indeed broken. For example, this happens for an input like ``` - 2 - - - 2 +2 +- +2 ``` When this solver cannot find a solution, it prints "`failed`". This @@ -93,29 +93,29 @@ solver cannot solve the input problem. Here is an example input of the former: ``` - 1 - 1 - - - 1 - 1 +1 +1 +- +1 +1 ``` There are two solutions: ``` - 11 + 11 - 1 X - 1 X +1 X +1 X ``` and ``` - 11 + 11 - 1 X - 1 X +1 X +1 X ``` ### Detail @@ -138,13 +138,13 @@ work for big problems. See: . -By its definition, the latter works for all human-solvable -problems. The issue of the latter approach is this kind of programs +By its definition, the latter method works for all human-solvable +problems. The issue of the latter approach is this kind of program tends to be lengthy. This approach still requires some [recursions](https://en.wikipedia.org/wiki/Recursion). The most difficult problems which are considered human-solvable may -require some "guesses". For this kind of problems, we need to assume a -cell is a space or a box, go ahead some steps with simple methods, +require some "guesses". For these kinds of problems, we need to assume a +cell is a space or a box, go ahead some steps with simple methods and mark the tried cell as a box (or a space if we assumed the tried cell is a box) if a contradiction is found. @@ -155,6 +155,7 @@ solver also runs a non-recursive guess for each undetermined cells. So, my program should be able to solve most human-solvable problems (assuming humans cannot execute deeper recursions). + ### Obfuscation First of all, as you see, my program looks like a nonogram puzzle which results @@ -175,6 +176,7 @@ characters are just wasted for numbers around the picture. The three requirements (dragon, speed, and size) naturally ended up with the well obfuscated code. + ### Portability This program uses two C99 features. One line comments and `long long`. @@ -187,11 +189,11 @@ cc -ansi -pedantic -std=c99 hamaji.c I checked my program with gcc-4.6.2 on linux, llvm-gcc-4.2 on Mac, and clang-3.0 on Mac. -Note that the behavior of `scanf()` differs on linux and mac, but this +Note that the behavior of `scanf(3)` differs on linux and mac, but this program supports both semantics. This program should not depend on `sizeof(int)`, `sizeof(void*)`, ASCII, -memory layout, undefined evaluation order (e.g., `a[i++]=i`), etc.\ +memory layout, undefined evaluation order (e.g., `a[i++]=i`), etc. This program won't work if the size of `long long` literal is less than 8. By grepping the source code of gcc @@ -201,6 +203,7 @@ grep LONG_LONG_TYPE_SIZE gcc/config/*/* I found long long may be 32bit integers only on AVR. + ### A few more things This code is considered as a [new year's postcard in diff --git a/2011/hamaji/conway-game-of-life.nono b/2011/hamaji/conway-game-of-life.nono new file mode 100644 index 000000000..d1cc7777e --- /dev/null +++ b/2011/hamaji/conway-game-of-life.nono @@ -0,0 +1,8 @@ +1 +1 +3 +- +1 +1.1 +2 + diff --git a/2011/hamaji/multi-solutions.nono b/2011/hamaji/multi-solutions.nono new file mode 100644 index 000000000..856d32672 --- /dev/null +++ b/2011/hamaji/multi-solutions.nono @@ -0,0 +1,5 @@ +1 +1 +- +1 +1 diff --git a/2011/hamaji/no-solution.nono b/2011/hamaji/no-solution.nono new file mode 100644 index 000000000..31107f7cc --- /dev/null +++ b/2011/hamaji/no-solution.nono @@ -0,0 +1,3 @@ +2 +_ +2 diff --git a/2011/hamaji/plus.nono b/2011/hamaji/plus.nono new file mode 100644 index 000000000..6d9056c6c --- /dev/null +++ b/2011/hamaji/plus.nono @@ -0,0 +1,13 @@ +2 +2 +6 +6 +2 +2 +- +2 +2 +6 +6 +2 +2 diff --git a/2011/hamaji/smiley.nono b/2011/hamaji/smiley.nono new file mode 100644 index 000000000..73856fe17 --- /dev/null +++ b/2011/hamaji/smiley.nono @@ -0,0 +1,31 @@ +5.5 +3.5.3 +2.9.2 +1.2.1.2.1 +1.11.1 +4.1.4 +4.1.4 +13 +6.6 +13 +1.2.2.1 +1.11.1 +2.9.2 +3.5.3 +5.5 +- +5.5 +3.5.3 +2.9.2 +1.11.1 +1.1.6.2.1 +2.1.3.3 +2.1.3.3 +7.1.3 +2.1.3.3 +2.1.3.3 +1.1.6.2.1 +1.11.1 +2.9.2 +3.5.3 +5.5 diff --git a/2011/hamaji/try.sh b/2011/hamaji/try.sh new file mode 100755 index 000000000..0e19d08d4 --- /dev/null +++ b/2011/hamaji/try.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2011/hamaji +# + +# 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: ./hamaji < dragon.nono (q = quit, space = next page): " +echo 1>&2 +./hamaji < dragon.nono | less -X +echo 1>&2 + +rm -f dragon dragon2 +echo "Checking if you have perl installed..." +PERL="$(type -P perl)" +if [[ -n "$PERL" ]]; then + echo "Perl installed, will generate output of ./hamaji < dragon.nono." + read -r -n 1 -p "Press any key to run: $PERL c2nono.pl hamaji.c | ./hamaji > dragon: " + echo 1>&2 + "$PERL" c2nono.pl hamaji.c | ./hamaji > dragon + read -r -n 1 -p "Press any key to run: ./hamaji < dragon.nono > dragon2: " + echo 1>&2 + ./hamaji < dragon.nono > dragon2 + read -r -n 1 -p "Press any key to run: diff -s dragon dragon2: " + echo 1>&2 + diff -s dragon dragon2 +fi +rm -f dragon dragon2 +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hamaji < random.nono: " +echo 1>&2 +./hamaji < random.nono +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hamaji < soccer.nono: " +echo 1>&2 +./hamaji < soccer.nono +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hamaji < codegolf.nono: " +echo 1>&2 +./hamaji < codegolf.nono +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hamaji < face.nono: " +echo 1>&2 +./hamaji < face.nono +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hamaji < penguin.nono: " +echo 1>&2 +./hamaji < penguin.nono +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hamaji < samurai.nono (q = quit, space = next page): " +echo 1>&2 +./hamaji < samurai.nono | less -X +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hamaji < conway-game-of-life.nono: " +echo 1>&2 +./hamaji < conway-game-of-life.nono +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hamaji < no-solution.nono (no solution): " +echo 1>&2 +./hamaji < no-solution.nono +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hamaji < multi-solutions.nono (> 1 solution): " +echo 1>&2 +./hamaji < multi-solutions.nono +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hamaji < plus.nono: " +echo 1>&2 +./hamaji < plus.nono +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hamaji < smiley.nono: " +echo 1>&2 +./hamaji < smiley.nono + +exit 0 diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 0b4294293..6d61ec566 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3238,6 +3238,18 @@ Cody also added the [try.sh](2011/goren/try.sh) script. Cody added the following words of wisdom: '"this" is not a pipe but "!" is'. +## [2011/hamaji](2011/hamaji/hamaji.c) ([README.md](2011/hamaji/README.md])) + +Cody added the [try.sh](2011/hamaji/try.sh) script and the `.nono` files +[conway-game-of-life.nono](2011/hamaji/conway-game-of-life.nono), +[multi-solutions.nono](2011/hamaji/multi-solutions.nono), +[no-solution.nono](2011/hamaji/no-solution.nono), +[plus.nono](2011/hamaji/plus.nono) and [smiley.nono](2011/hamaji/smiley.nono). +The latter two `.nono` files were taken from + +and the others were from the authors' remarks. + + ## [2011/hou](2011/hou/hou.c) ([README.md](2011/hou/README.md])) Cody added the [try.sh](2011/hou/try.sh) script.