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.
This commit is contained in:
Cody Boone Ferguson committed 2023-11-28 09:56:18 -08:00
1 parent 596b1604ee
commit c7c274e5e0
8 files changed
+215 -45

No files matched your search

+48 -45
View File
@@ -15,22 +15,23 @@ make
### Try: ### Try:
```sh ```sh
./hamaji < dragon.nono ./try.sh
./hamaji < random.nono ```
./hamaji < soccer.nono
./hamaji < codegolf.nono If you have perl installed you should be able to reproduce
./hamaji < face.nono [dragon.nono](dragon.nono) like:
./hamaji < penguin.nono
./hamaji < samurai.nono ```sh
perl c2nono.pl hamaji.c | ./hamaji
``` ```
## Judges' remarks: ## 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
<http://en.wikipedia.org/wiki/Nonogram>. 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 some to be good luck. Well it was certainly true that the
IOCCC was lucky to get such a fine submission! 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! files and then compare your solution with this program!
NOTE: NONOGRAM (r) is a registered Trademark and is used with permission. See NOTE: NONOGRAM (r) is a registered Trademark and is used with permission. See
<https://web.archive.org/web/20110128130704/http://nonogram.com/> for more <https://nonogram.com> for more information.
information.
## Author's remarks: ## 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): Game of Life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life):
``` ```
1 1
. .
112 112
1 X 1 X
1 X 1 X
3 XXX 3 XXX
``` ```
the input should be the input should be
``` ```
1 1
1 1
3 3
- -
1 1
1.1 1.1
2 2
``` ```
The width and the height of an input puzzle should be less than or 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 an input like
``` ```
2 2
- -
2 2
``` ```
When this solver cannot find a solution, it prints "`failed`". This 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: former:
``` ```
1 1
1 1
- -
1 1
1 1
``` ```
There are two solutions: There are two solutions:
``` ```
11 11
1 X 1 X
1 X 1 X
``` ```
and and
``` ```
11 11
1 X 1 X
1 X 1 X
``` ```
### Detail ### Detail
@@ -138,13 +138,13 @@ work for big problems.
See: <http://ccl.northwestern.edu/netlogo/models/community/Nonogram>. See: <http://ccl.northwestern.edu/netlogo/models/community/Nonogram>.
By its definition, the latter works for all human-solvable By its definition, the latter method works for all human-solvable
problems. The issue of the latter approach is this kind of programs problems. The issue of the latter approach is this kind of program
tends to be lengthy. This approach still requires some tends to be lengthy. This approach still requires some
[recursions](https://en.wikipedia.org/wiki/Recursion). The [recursions](https://en.wikipedia.org/wiki/Recursion). The
most difficult problems which are considered human-solvable may most difficult problems which are considered human-solvable may
require some "guesses". For this kind of problems, we need to assume a 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, 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 mark the tried cell as a box (or a space if we assumed the tried cell
is a box) if a contradiction is found. 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 program should be able to solve most human-solvable problems (assuming humans
cannot execute deeper recursions). cannot execute deeper recursions).
### Obfuscation ### Obfuscation
First of all, as you see, my program looks like a nonogram puzzle which results 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 The three requirements (dragon, speed, and size) naturally ended up
with the well obfuscated code. with the well obfuscated code.
### Portability ### Portability
This program uses two C99 features. One line comments and `long long`. 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 I checked my program with gcc-4.6.2 on linux, llvm-gcc-4.2 on Mac, and
clang-3.0 on Mac. 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. program supports both semantics.
This program should not depend on `sizeof(int)`, `sizeof(void*)`, ASCII, 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. This program won't work if the size of `long long` literal is less than 8.
By grepping the source code of gcc 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. I found long long may be 32bit integers only on AVR.
### A few more things ### A few more things
This code is considered as a [new year's postcard in This code is considered as a [new year's postcard in
+8
View File
@@ -0,0 +1,8 @@
1
1
3
-
1
1.1
2
+5
View File
@@ -0,0 +1,5 @@
1
1
-
1
1
+3
View File
@@ -0,0 +1,3 @@
2
_
2
+13
View File
@@ -0,0 +1,13 @@
2
2
6
6
2
2
-
2
2
6
6
2
2
+31
View File
@@ -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
+95
View File
@@ -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
+12
View File
@@ -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'. 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
<https://web.archive.org/web/20130218055139/http://codegolf.com/paint-by-numbers>
and the others were from the authors' remarks.
## [2011/hou](2011/hou/hou.c) ([README.md](2011/hou/README.md])) ## [2011/hou](2011/hou/hou.c) ([README.md](2011/hou/README.md]))
Cody added the [try.sh](2011/hou/try.sh) script. Cody added the [try.sh](2011/hou/try.sh) script.