Format and link fix 2011/hamaji/README.md

This commit is contained in:
Cody Boone Ferguson committed 2023-05-03 06:08:25 -07:00
1 parent b2602712a6
commit 0497f58748
1 file changed
+69 -52
+69 -52
View File
@@ -1,7 +1,7 @@
# Best solved puzzle
Shinichiro Hamaji
<shinichiro.hamaji@gmail.com>
Shinichiro Hamaji
<shinichiro.hamaji@gmail.com>
## To build:
@@ -30,29 +30,29 @@ make
## Judges' remarks:
This program solves "Nonogram", which also known as "Paint by Numbers":
<http://en.wikipedia.org/wiki/Nonogram>
<http://en.wikipedia.org/wiki/Nonogram>.
This entry roar 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!
The source code is a solution to a Paint by Numbers puzzle when you
paint by C. Try your hand at solving a few of the other .nono
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 http://nonogram.com/ for more information.
NOTE: NONOGRAM (r) is a registered Trademark and is used with permission. See
<https://web.archive.org/web/20110128130704/http://nonogram.com/> for more
information.
## Author's remarks:
The format of the input files are as same as this site:
<https://web.archive.org/web/20130218055139/http://codegolf.com/paint-by-numbers>.
<http://codegolf.com/paint-by-numbers>
For example, for a simple problem which shows a glider of [conway's
lifegame](http://en.wikipedia.org/wiki/Conway's_Game_of_Life).
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
@@ -61,8 +61,11 @@ lifegame](http://en.wikipedia.org/wiki/Conway's_Game_of_Life).
1 X
3 XXX
```
the input should be
```
1
1
3
@@ -70,63 +73,76 @@ the input should be
1
1.1
2
```
The width and the height of an input puzzle should be less than or
equal to 60.
When this solver finds the problem has no solution, it prints "invalid".
When this solver finds the problem has no solution, it prints "`invalid`".
This means the problem is indeed broken. For example, this happens for
an input like
```
2
-
2
```
When this solver cannot find a solution, it prints "failed". This
When this solver cannot find a solution, it prints "`failed`". This
failure can happen when the problem has more than one solution or the
solver cannot solve the input problem. Here is an example input of the
former:
```
1
1
-
1
1
```
There are two solutions:
```
11
1 X
1 X
```
and
```
11
1 X
1 X
```
### Detail
Solving Nonogram is known NP-complete, so we cannot make a solver
which solves all puzzles. However, we can write a solver which solves
most problems solvable by humans. There are a bunch of ways to write
such programs. The two most obvious approaches are:
Solving Nonogram is
[NP-complete](https://en.wikipedia.org/wiki/NP-completeness), so we cannot make
a solver which solves all puzzles. However, we can write a solver which solves
most problems solvable by humans. There are a bunch of ways to write such
programs. The two most obvious approaches are:
1. Check all possible solutions with backtracking.
2. Implement all techniques which humans use.
The former, brute-force approach is easy to implement. However, it
works only for smaller problems (width and height should be at most 30
or so). Similarly, using generic probabilistic metaheuristics such as
simulated annealing doesn't work for big problems.
or so). Similarly, using generic probabilistic
[metaheuristics](https://en.wikipedia.org/wiki/Metaheuristic) such as
[simulated annealing](https://en.wikipedia.org/wiki/Simulated_annealing) doesn't
work for big problems.
<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
problems. The issue of the latter approach is this kind of programs
tends to be lengthy. This approach still requires some recursions. The
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,
@@ -134,19 +150,19 @@ mark the tried cell as a box (or a space if we assumed the tried cell
is a box) if a contradiction is found.
My program uses an approach like "Set based solver" introduced in
[http://www.haskell.org/haskellwiki/Nonogram](http://www.haskell.org/haskellwiki/Nonogram) .
This should be equivalent to the combinations of simple methods (no
advanced reasoning with guess). My solver also runs 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).
<https://wiki.haskell.org/Nonogram#Set_based_solver>. This should be equivalent
to the combinations of simple methods (no advanced reasoning with guess). My
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 a dragon. This puzzle is "dragon.nono" in this
directory. Note that whitespaces in character literals, a string
literal, and around the last comment are considered as a boxed cell.
First of all, as you see, my program looks like a nonogram puzzle which results
in a [dragon](https://www.draconika.com/what). This puzzle is
[dragon.nono](dragon.nono) in this directory. Note that whitespaces in character
literals, a string literal, and around the last comment are considered as a
boxed cell.
My program is based on bit operations for speed. Many values are
stored using negative logic (0 means on and 1 means off) to utilize
@@ -162,22 +178,22 @@ with the well obfuscated code.
### Portability
This program uses two C99 features. One line comments and "long long".
GCC's "-ansi -pedantic" check should pass:
This program uses two C99 features. One line comments and `long long`.
GCC's `-ansi -pedantic` check should pass:
```sh
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.
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()` 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.
This program won't work if the size of long long literal is less than 8.
This program should not depend on `sizeof(int)`, `sizeof(void*)`, ASCII,
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
```sh
@@ -186,25 +202,26 @@ grep LONG_LONG_TYPE_SIZE gcc/config/*/*
I found long long may be 32bit integers only on AVR.
### A few more
### A few more things
This code is considered as a new year's postcard in Japan. We chose
the dragon because 2012 is the year of dragon.
<http://en.wikipedia.org/wiki/Japanese_New_Year#Postcards>
This code is considered as a [new year's postcard in
Japan](http://en.wikipedia.org/wiki/Japanese_New_Year#Postcards). We chose
the dragon because 2012 is the [year of
dragon](https://japanesezodiac.com/japanese-year-of-the-dragon).
The second author wrote the picture, and the first author did
everything else.
The dragon.nono, samurai.nono, and penguin.nono was written by the
second author. The soccer.nono was from a wikipedia entry. This file
is important because it requires some guesses. The random.nono file
was randomly generated. The codegolf.nono and face.nono have borrowed
from this site:
The [dragon.nono](dragon.nono), [samurai.nono](samurai.nono), and
[penguin.nono](penguin.nono) were written by the
second author. The [soccer.nono](soccer.nono) was from a wikipedia entry. This file
is important because it requires some guesses. The [random.nono](random.nono) file
was randomly generated. The [codegolf.nono](codegolf.nono) and
[face.nono](face.nono) were taken from
<https://web.archive.org/web/20130218055139/http://codegolf.com/paint-by-numbers>.
<http://codegolf.com/paint-by-numbers>
You can reproduce dragon.nono from hamaji.c using c2nono.pl:
You can reproduce [dragon.nono](dragon.nono) from [hamaji.c](hamaji.c) using
[c2nono.pl](c2nono.pl):
```sh
perl c2nono.pl hamaji.c | ./hamaji