Merge pull request #1579 from xexyl/blakely11
Add 2011/blakely/try.sh + format/typo checks
This commit is contained in:
18 files changed
+418
-107
No files matched your search
@@ -88,11 +88,7 @@ puzzles in wikipedia](http://en.wikipedia.org/wiki/Bedlam_cube).
|
||||
Some instructions on how to make your own cube are in the included file
|
||||
[bedlam-cubes.pdf](bedlam-cubes.pdf).
|
||||
|
||||
Finally, you can watch it being solved:
|
||||
|
||||

|
||||
|
||||
...taken from <https://www.youtube.com/watch?v=a8s1AcYMLBc>.
|
||||
Finally, you can watch it being solved at <https://www.youtube.com/watch?v=a8s1AcYMLBc>.
|
||||
|
||||
Actually the cube is very hard to do by hand by just trying to fit it
|
||||
together. I have not known anyone to solve it in this way - you would
|
||||
|
||||
+41
-26
@@ -17,12 +17,18 @@ Zoom out and make your terminal window 53 or more lines deep.
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
./blakely < 3.dat | head -100
|
||||
./blakely - < 3.dat | head -40
|
||||
./blakely < evolve_to_3.dat | head -55
|
||||
./try.sh
|
||||
```
|
||||
|
||||
For those who have a lot of time, try:
|
||||
|
||||
```sh
|
||||
./blakely < t0_3.dat
|
||||
```
|
||||
|
||||
though one might or might not need to kill it, depending on your boredom
|
||||
threshold.
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
@@ -31,7 +37,7 @@ This program plays [Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)
|
||||
if given its own source as input, and allows to check if your garden
|
||||
is a [Garden of Eden](http://en.wikipedia.org/wiki/Garden_of_Eden_%28cellular_automaton%29), all in one source.
|
||||
|
||||
If you have enough time to spare, put the plan of your garden in a text file,\
|
||||
If you have enough time to spare, put the plan of your garden in a text file,
|
||||
and run:
|
||||
|
||||
```sh
|
||||
@@ -41,9 +47,10 @@ and run:
|
||||
|
||||
## Author's remarks:
|
||||
|
||||
This program uses a well-known algorithm in order to display pi to
|
||||
fifteen decimal places. The source-layout itself demonstrates the importance of
|
||||
using the correct amount of whitespace in code and the clear superiority of spaces over tabs.
|
||||
This program uses a well-known algorithm in order to display pi to fifteen
|
||||
decimal places. The source-layout itself demonstrates the importance of using
|
||||
the correct amount of whitespace in code and the clear superiority of spaces
|
||||
over tabs.
|
||||
|
||||
In order to see the main feature of the code, type:
|
||||
|
||||
@@ -56,6 +63,7 @@ results are best viewed in a terminal window at least 60 characters
|
||||
high and wide. Alternatively, redirect the output to a separate file
|
||||
(killing when necessary).
|
||||
|
||||
|
||||
### Overview
|
||||
|
||||
The program emulates John Conway's cellular automaton known as "[The Game of
|
||||
@@ -69,8 +77,8 @@ other feature of the program which can be demonstrated as follows:
|
||||
```
|
||||
|
||||
The program will first display the grid given in [3.dat](3.dat), and then three
|
||||
more grids (taking a few minutes to display the last). Waiting for any more grids will
|
||||
take a substantial amount of time. The final grid has been put into
|
||||
more grids (taking a few minutes to display the last). Waiting for any more
|
||||
grids will take a substantial amount of time. The final grid has been put into
|
||||
[evolve_to_3.dat](evolve_to_3.dat), and if you type
|
||||
|
||||
```sh
|
||||
@@ -79,7 +87,7 @@ take a substantial amount of time. The final grid has been put into
|
||||
|
||||
then the 3 will reappear after three time steps.
|
||||
|
||||
As should now be clear, this use of program will attempt to evolve a given setup
|
||||
As should now be clear, this use of the program will attempt to evolve a given setup
|
||||
backwards in time according to the Life rules. The resulting grid is clearly not
|
||||
necessarily unique. The program will evolve backwards given *any* single command
|
||||
line option.
|
||||
@@ -90,6 +98,7 @@ will stop if it is unable to find a grid that will evolve to the
|
||||
current layout correctly. This can be seen with the sample grid
|
||||
[t0_3.dat](t0_3.dat), which evolves backwards by only two time-steps.
|
||||
|
||||
|
||||
### Input file format
|
||||
|
||||
The input files must encode a square grid, where a space is a dead cell, and any
|
||||
@@ -99,6 +108,7 @@ last line. When designing grids, it may help to type full-stops (dots) in place
|
||||
of spaces, and do a global replace afterwards. Any deviation from this format
|
||||
will cause errors in the output.
|
||||
|
||||
|
||||
### Limitations
|
||||
|
||||
This is only an approximation to the original Life, as it takes place
|
||||
@@ -115,6 +125,7 @@ segfault), but changing the two `9802`s to `MAX_SIZE*MAX_SIZE+1` will
|
||||
solve this, although some reformatting of the code might have to be done to allow
|
||||
larger numbers.
|
||||
|
||||
|
||||
### Compiler warnings/assumptions
|
||||
|
||||
When compiled with the `-Wall -pedantic -ansi` options of gcc, some warnings
|
||||
@@ -128,6 +139,7 @@ system is required to run it. Also, as mentioned above, any system that uses
|
||||
anything other than a plain `\n` to end a line will cause problems when reading
|
||||
in files.
|
||||
|
||||
|
||||
### Obfuscation
|
||||
|
||||
Given the finely-tuned layout required to evolve into pi, this is one of the
|
||||
@@ -151,7 +163,8 @@ Other obfuscations used are:
|
||||
- Needlessly recursive functions.
|
||||
- Use of bitwise-operations.
|
||||
- Storing a variable whose value could easily be found from another.
|
||||
- Use of `goto`s to emulate a for loop.
|
||||
- Use of `goto`s to emulate a `for` loop.
|
||||
|
||||
|
||||
### Algorithm
|
||||
|
||||
@@ -177,20 +190,22 @@ Since this uses brute-force, it can be very slow. (In fact, the
|
||||
various obfuscations have, at least for the gcc compiler,
|
||||
caused a substantial slowdown.)
|
||||
|
||||
|
||||
### Program layout
|
||||
|
||||
The "calculation" of pi was chosen purely because algorithms to find
|
||||
pi are numerous, but the [Game of
|
||||
Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) is rarely (if ever?) used for
|
||||
this purpose. Also, separate digits made determining the layout somewhat easier.
|
||||
The "calculation" of pi was chosen purely because algorithms to find pi are
|
||||
numerous, but the [Game of
|
||||
Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) is rarely (if
|
||||
ever?) used for this purpose. Also, separate digits made determining the layout
|
||||
somewhat easier.
|
||||
|
||||
Deriving the layout was the most complicated part of the program. As is clear from
|
||||
the final layout featuring pi, the grid was divided into sixteen squares,
|
||||
and layouts that would evolve to each of the nine digits required were
|
||||
found. (This used the three-by-five digit-layout embedded in, at first, a
|
||||
nine-by-nine grid, then in larger grids, until fifteen-by-fifteen was
|
||||
reached.) The fifteen-by-fifteen grids give enough blank cells around
|
||||
them that the digits will not collide when evolving.
|
||||
Deriving the layout was the most complicated part of the program. As is clear
|
||||
from the final layout featuring pi, the grid was divided into sixteen squares,
|
||||
and layouts that would evolve to each of the nine digits required were found.
|
||||
(This used the three-by-five digit-layout embedded in, at first, a nine-by-nine
|
||||
grid, then in larger grids, until fifteen-by-fifteen was reached.) The
|
||||
fifteen-by-fifteen grids give enough blank cells around them that the digits
|
||||
will not collide when evolving.
|
||||
|
||||
However, this did not allow for sufficient characters to fit the code
|
||||
into. Therefore it was necessary to add some regions that would quickly die off
|
||||
@@ -198,14 +213,14 @@ without expanding to collide with the digits' evolution.
|
||||
Groups of cells such as singletons, pairs, and larger groups like
|
||||
|
||||
```
|
||||
* * * * * * * * * *
|
||||
*****************
|
||||
* * * * * * * * * *
|
||||
* * * * * * * * * *
|
||||
*****************
|
||||
* * * * * * * * * *
|
||||
```
|
||||
|
||||
were useful in this regard.
|
||||
|
||||
Other problems were given by keywords which need to be all in one
|
||||
Other problems were keywords which need to be all in one
|
||||
string, keywords requiring space after them, and
|
||||
multi-character tokens. Some of these problems were dealt with by
|
||||
using the `#define`s and `#include`s given in the build-script, as there
|
||||
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 2011/blakely
|
||||
#
|
||||
|
||||
# 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: ./blakely < 3.dat | head -100: "
|
||||
echo 1>&2
|
||||
./blakely < 3.dat | head -100
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./blakely - < 3.dat | head -40: "
|
||||
echo 1>&2
|
||||
./blakely - < 3.dat | head -40
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./blakely < evolve_to_3.dat | head -55: "
|
||||
echo 1>&2
|
||||
./blakely < evolve_to_3.dat | head -55
|
||||
+13
-11
@@ -28,7 +28,7 @@ NOTE: to restore your cursor in your shell, try `reset`.
|
||||
This round program will generate a classic spherical result!
|
||||
|
||||
You will need a terminal capable of displaying coloured ANSI
|
||||
characters (for example an xterm or a Terminal.app window).
|
||||
characters (for example an xterm or a Terminal.app window in macOS).
|
||||
|
||||
You might also want to turn off any scrollback history. The program will
|
||||
size itself to the initial geometry of your terminal.
|
||||
@@ -41,7 +41,7 @@ large for hi-res graphics!
|
||||
|
||||
This program uses ANSI graphics to recreate the classic Boing Ball demo from
|
||||
the Commodore Amiga. See <https://www.youtube.com/watch?v=-ga41edXw3A> if you
|
||||
aren't familiar with it. Back in its day, this demo inspired lust and awe in
|
||||
aren't familiar with it. Back in its day, this demo inspired lust and awe in
|
||||
geeks around the world.
|
||||
|
||||
The graphics are
|
||||
@@ -61,11 +61,13 @@ To compile:
|
||||
cc -lm eastman.c
|
||||
```
|
||||
|
||||
|
||||
### Portability
|
||||
|
||||
It should be completely portable. I've tested with gcc on Mac OS X 10.7 (Lion)
|
||||
and Fedora 10. I would expect it to work in any Unix-like environment.
|
||||
|
||||
|
||||
### Obfuscation
|
||||
|
||||
I have merged expressions wherever possible, making extensive use of ternary
|
||||
@@ -75,22 +77,22 @@ evaluations, is a single expression involving 41 operators.
|
||||
|
||||
Variables are named alphabetically in the order they are declared.
|
||||
|
||||
The third argument to `ioctl()` should really be a `struct winsize`, and I should
|
||||
then look up the `ws_row` and `ws_col` fields, but that makes it way too obvious
|
||||
what I'm doing there. Since a `struct winsize` just contains four unsigned shorts, I
|
||||
replaced it with an array. And since all the values will be much less than
|
||||
`32767`, I further simplified the type to just `short[]`.
|
||||
The third argument to `ioctl(2)` should really be a `struct winsize`, and I
|
||||
should then look up the `ws_row` and `ws_col` fields, but that makes it way too
|
||||
obvious what I'm doing there. Since a `struct winsize` just contains four
|
||||
`unsigned short`s, I replaced it with an array. And since all the values will
|
||||
be much less than `32767`, I further simplified the type to just `short[]`.
|
||||
|
||||
A wonderful thing about ANSI graphics is that it produces nearly unintelligible
|
||||
code. Consider the printf spec to print a single space in a desired color:
|
||||
code. Consider the `printf(3)` spec to print a single space in a desired color:
|
||||
`"\x1B[%dm `. I could have done something to further obfuscate it, but it's
|
||||
already indistinguishable from line noise, so why bother?
|
||||
|
||||
There are lots of other minor obfuscations to make the code less obvious. For
|
||||
example, I could have written the outer loop as `while(1)`, but why write a 1
|
||||
when I can calculate it from the return value of `usleep()` instead? And I could
|
||||
have written `usleep(80000)`, but `usleep(79383)` just looks so much better.
|
||||
And so on.
|
||||
when I can calculate it from the return value of `usleep(3)` instead? And I
|
||||
could have written `usleep(80000)`, but `usleep(79383)` just looks so much
|
||||
better. And so on.
|
||||
|
||||
|
||||
## Copyright and CC BY-SA 4.0 License:
|
||||
|
||||
Binary file not shown.
+36
-19
@@ -5,6 +5,17 @@ make
|
||||
```
|
||||
|
||||
|
||||
### Bugs and (Mis)features:
|
||||
|
||||
The current status of this entry is:
|
||||
|
||||
```
|
||||
STATUS: INABIAF - please **DO NOT** fix
|
||||
```
|
||||
|
||||
For more detailed information see [2011 fredriksson in bugs.md](/bugs.md#2011-fredriksson).
|
||||
|
||||
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
@@ -15,13 +26,12 @@ make
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
./fredriksson -k1 -i POOT < /etc/group
|
||||
ulimit -s unlimited
|
||||
./fredriksson -k2 -t -n bofuskate < /usr/share/dict/words
|
||||
./try.sh
|
||||
```
|
||||
|
||||
NOTE: you need to be allowed to change your stack size or else the last command
|
||||
will likely cause the program to dump core.
|
||||
in the script would likely cause the program to dump core, which is why the
|
||||
script checks the exit code of `ulimit` first.
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
@@ -36,10 +46,12 @@ program and calls it. As an exercise, try writing the compressor.
|
||||
|
||||
## Author's remarks:
|
||||
|
||||
|
||||
### Approximate grep
|
||||
|
||||
Implements a variant of `grep`.
|
||||
|
||||
|
||||
### Usage
|
||||
|
||||
To search regexp from file, do:
|
||||
@@ -69,8 +81,8 @@ This version of `grep` recognizes two more options, not present in normal
|
||||
"`obfuscated`" matches "`obfuscation`"
|
||||
with one deletion and two mismatches. Likewise, "`obfuscate`" and
|
||||
"`oversimplify`" match with 7 [edit
|
||||
operations](https://en.wikipedia.org/wiki/Edit_distance#Formal_definition_and_properties). The default is `-k0`
|
||||
(i.e. exact match).
|
||||
operations](https://en.wikipedia.org/wiki/Edit_distance#Formal_definition_and_properties).
|
||||
The default is `-k0` (i.e. exact match).
|
||||
|
||||
* `-t` Add local transpositions to the set of allowed
|
||||
[edit-operations](https://en.wikipedia.org/wiki/Edit_distance#Formal_definition_and_properties).
|
||||
@@ -82,7 +94,8 @@ Of course, one could construct a standard
|
||||
[regexp](https://www.regular-expressions.info) that matches the same
|
||||
patterns, but the problem is that such a regexp grows exponentially in
|
||||
size when the number of allowed [edit
|
||||
operations](https://en.wikipedia.org/wiki/Edit_distance#Formal_definition_and_properties) is increased.
|
||||
operations](https://en.wikipedia.org/wiki/Edit_distance#Formal_definition_and_properties)
|
||||
is increased.
|
||||
|
||||
This version does not recognize all regular expressions, but the
|
||||
following are allowed:
|
||||
@@ -104,11 +117,13 @@ otherwise this is not needed. Note that the syntax differs from standard
|
||||
(?) grep a bit, i.e. in plain grep you can use `]` and `-` in bracket
|
||||
expressions by putting `]` as the first character, and putting `-` last.
|
||||
|
||||
|
||||
### Other uses
|
||||
|
||||
* You can use this in place of [cat](https://en.wikipedia.org/wiki/Cat_(Unix)).
|
||||
Just say
|
||||
|
||||
|
||||
```sh
|
||||
./fredriksson -k3 cat < file
|
||||
```
|
||||
@@ -119,6 +134,7 @@ Just say
|
||||
./fredriksson -nk3 cat < file
|
||||
```
|
||||
|
||||
|
||||
### Other features
|
||||
|
||||
* It is assumed that the user knows how to feed correct input to the
|
||||
@@ -132,6 +148,7 @@ Just say
|
||||
liners in IOCCC entries, just adjust your stack size to a suitable
|
||||
threshold, and search for "`ioccc`", with option `-vk5`.
|
||||
|
||||
|
||||
### Limitations and remarks
|
||||
|
||||
* Using warning options (such as `-Wall`) when building gives a lot of warning,
|
||||
@@ -142,7 +159,7 @@ Just say
|
||||
Please ignore them all, since they just try to tell you that the source
|
||||
is obfuscated.
|
||||
|
||||
* Only standard input is handled. And _only_ if stdin comes from a file,
|
||||
* Only standard input is handled. And _only_ if `stdin` comes from a file,
|
||||
i.e. pipes may or may not work. If you want to count only (`-c` option),
|
||||
then this shouldn't be an issue.
|
||||
|
||||
@@ -157,7 +174,7 @@ Just say
|
||||
* Depending on the file, it might require a lot of stack space. If the
|
||||
program segfaults (because of this), say
|
||||
|
||||
ulimit -s unlimited
|
||||
ulimit -s unlimited
|
||||
|
||||
cross your fingers, hope it is enough, and try again.
|
||||
|
||||
@@ -199,26 +216,26 @@ Just say
|
||||
corresponding binary after running it, but this feature was removed
|
||||
from the submitted entry.)
|
||||
|
||||
* The code demonstrates several useful programming paradigms, such as
|
||||
* The code demonstrates several useful programming paradigms, such as:
|
||||
- recursion to remove all loops
|
||||
- subroutines (`main()` contains several logical subroutines,
|
||||
selected by the first argument)
|
||||
- function pointers
|
||||
|
||||
* Algorithmically, it incorporates the following
|
||||
- (inverse) Burrows-Wheeler transform (used also e.g. in bzip2)
|
||||
* Algorithmically, it incorporates the following:
|
||||
- (inverse) Burrows-Wheeler transform (used also e.g. in `bzip2(1)`)
|
||||
- data compression (really expansion :-), run-length-encoding,
|
||||
unary coding (this is why it is expansion rather than compression)
|
||||
- approximate string matching
|
||||
- dynamic programming to compute the edit distance
|
||||
- parallel computation in sequential computers (by packing
|
||||
several objects into a single long, to speed up the dynamic
|
||||
several objects into a single `long`, to speed up the dynamic
|
||||
programming)
|
||||
- self extracting, compiling and running code
|
||||
|
||||
* As a C program, it demonstrates that
|
||||
- a C subset without reserved words is complete enough,
|
||||
(excluding data type specific things (`int`, `char`, `void` ...))
|
||||
excluding data type specific things (`int`, `char`, `void` ...)
|
||||
- only letters are needed (i.e. the digits `0-9` are not)
|
||||
- only one statement is enough to code any program (plus
|
||||
variable definitions)
|
||||
@@ -255,18 +272,18 @@ Just say
|
||||
|
||||
One reason for this is that the code builds (some of the) constant
|
||||
values from string literal `"\b"`, except that the backspace `\b` is not
|
||||
escaped like that; the source uses the raw ascii value (010 octal) instead.
|
||||
escaped like that; the source uses the raw ASCII value (`010` octal) instead.
|
||||
Thus when viewing with cat or something, that backspace erases the leading
|
||||
quotation mark. Makes it appear uncompilable, and it is: if you copy-paste
|
||||
the cat output from terminal to some editor, save it, the result would not
|
||||
compile.
|
||||
|
||||
Some other constants are built from ASCII values of chars.
|
||||
Some other constants are built from ASCII values of `char`s.
|
||||
|
||||
Besides of making the code hard to read, all this makes it also quite large.
|
||||
|
||||
* Running it through GNU indent or bcpp (C beautifiers) does not beautify
|
||||
it a bit. In fact, indent makes it only worse (at least with the default
|
||||
* Running it through GNU `indent(1)` or `bcpp(1)` (C beautifiers) does not beautify
|
||||
it a bit. In fact, `indent` makes it only worse (at least with the default
|
||||
options). Running it through the preprocessor does basically nothing,
|
||||
since no `#define`s are used.
|
||||
|
||||
@@ -276,7 +293,7 @@ Just say
|
||||
program exceeds the 2048 limit. However, whitespace is whitespace and
|
||||
the rules did not specify that these must be in between the statements.
|
||||
A character is a whitespace if `isspace()` returns non-zero value. Even
|
||||
if deleting even one of those chars breaks the program! (This does not
|
||||
if deleting even one of those chars it breaks the program! (This does not
|
||||
apply to the generated source `ag.c`.)
|
||||
|
||||
|
||||
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 2011/fredriksson
|
||||
#
|
||||
|
||||
# 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 "$ ./fredriksson -k3 cat < fredriksson.c" 1>&2
|
||||
read -r -n 1 -p "Press any key to have the program show its source code: "
|
||||
echo 1>&2
|
||||
./fredriksson -k3 cat < fredriksson.c
|
||||
|
||||
read -r -n 1 -p "Press any key to continue: "
|
||||
echo 1>&2
|
||||
read -r -n 1 -p "Press any key to run: ./fredriksson -k1 -i POOT < /etc/group: "
|
||||
echo 1>&2
|
||||
./fredriksson -k1 -i POOT < /etc/group
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./fredriksson -ck0 [0-9] < fredriksson.c: "
|
||||
echo 1>&2
|
||||
./fredriksson -ck0 [0-9] < fredriksson.c
|
||||
echo 1>&2
|
||||
|
||||
read -r -n 1 -p "Press any key to run: ./fredriksson -ck0 [0-9] < ag.c: "
|
||||
echo 1>&2
|
||||
./fredriksson -ck0 [0-9] < ag.c
|
||||
|
||||
echo "Trying to set unlimited stack space for this process..." 1>&2
|
||||
ulimit -s unlimited 2>/dev/null
|
||||
if [[ "$?" -ne 0 ]]; then
|
||||
echo "...couldn't set unlimited stack space, will skip command." 1>&2
|
||||
else
|
||||
read -r -n 1 -p "Press any key to run: ./fredriksson -k2 -t -n bofuskate < /usr/share/dict/words: "
|
||||
./fredriksson -k2 -t -n bofuskate < /usr/share/dict/words
|
||||
fi
|
||||
@@ -1,3 +1,5 @@
|
||||
hamaji
|
||||
hamaji.orig
|
||||
prog.orig
|
||||
dragon
|
||||
dragon2
|
||||
+48
-45
@@ -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":
|
||||
<http://en.wikipedia.org/wiki/Nonogram>.
|
||||
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
|
||||
<https://web.archive.org/web/20110128130704/http://nonogram.com/> for more
|
||||
information.
|
||||
<https://nonogram.com> 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: <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
|
||||
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
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
1
|
||||
1
|
||||
3
|
||||
-
|
||||
1
|
||||
1.1
|
||||
2
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
1
|
||||
1
|
||||
-
|
||||
1
|
||||
1
|
||||
@@ -0,0 +1,3 @@
|
||||
2
|
||||
_
|
||||
2
|
||||
@@ -0,0 +1,13 @@
|
||||
2
|
||||
2
|
||||
6
|
||||
6
|
||||
2
|
||||
2
|
||||
-
|
||||
2
|
||||
2
|
||||
6
|
||||
6
|
||||
2
|
||||
2
|
||||
@@ -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
|
||||
Executable
+95
@@ -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
|
||||
@@ -2488,6 +2488,17 @@ tends to result in empty output.
|
||||
If you want to try and fix this (mis)feature, you are welcome to try.
|
||||
|
||||
|
||||
## 2011 fredriksson
|
||||
|
||||
### STATUS: INABIAF - please **DO NOT** fix
|
||||
### Source code: [2011/fredriksson/fredriksson.c](2011/fredriksson/fredriksson.c)
|
||||
### Information: [2011/fredriksson/README.md](2011/fredriksson/README.md)
|
||||
|
||||
The author stated that there are a number of features and limitations. As the
|
||||
list is rather long see [other
|
||||
features](2011/fredriksson/README.md#other-features) and [limitations and
|
||||
remarks](2011/fredriksson/README.md#limitations-and-remarks) instead.
|
||||
|
||||
|
||||
## 2011 richards
|
||||
|
||||
|
||||
@@ -3211,6 +3211,11 @@ We're not able to test this.
|
||||
Cody added the [try.sh](2011/akari/try.sh) script.
|
||||
|
||||
|
||||
## [2011/blakely](2011/blakely/blakely.c) ([README.md](2011/blakely/README.md]))
|
||||
|
||||
Cody added the [try.sh](2011/blakely/try.sh) script.
|
||||
|
||||
|
||||
## [2011/borsanyi](2011/borsanyi/borsanyi.c) ([README.md](2011/borsanyi/README.md]))
|
||||
|
||||
Cody, out of an abundance of caution, added a second arg to `main()` as some
|
||||
@@ -3225,6 +3230,17 @@ Cody also added the [try.sh](2011/borsanyi/try.sh) script.
|
||||
Cody added the [try.sh](2011/dlowe/try.sh) script.
|
||||
|
||||
|
||||
## [2011/eastman](2011/eastman/eastman.c) ([README.md](2011/eastman/README.md]))
|
||||
|
||||
Cody added the video file [boing-ball.mp4](2011/eastman) which is the demo the
|
||||
author referred to.
|
||||
|
||||
|
||||
## [2011/fredriksson](2011/fredriksson/fredriksson.c) ([README.md](2011/fredriksson/README.md]))
|
||||
|
||||
Cody added the [try.sh](2011/fredriksson/try.sh) script.
|
||||
|
||||
|
||||
## [2011/goren](2011/goren/goren.c) ([README.md](2011/goren/README.md]))
|
||||
|
||||
Cody fixed this for macOS. Before the fix it segfaulted. It worked fine under
|
||||
@@ -3238,6 +3254,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
|
||||
<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]))
|
||||
|
||||
Cody added the [try.sh](2011/hou/try.sh) script.
|
||||
|
||||
+6
-1
@@ -1,5 +1,5 @@
|
||||
# A todo list of known things to check and/or do
|
||||
*Last updated: Sat 25 Nov 2023 19:01:07 UTC*
|
||||
*Last updated: Tue 28 Nov 2023 18:20:54 UTC*
|
||||
|
||||
This document is primarily for [Cody Boone
|
||||
Ferguson](/winners.html#Cody_Boone_Ferguson) as he (that is I :-) ) wanted a way
|
||||
@@ -160,3 +160,8 @@ that has had this done is [1985/lycklama](1985/lycklama/README.md).
|
||||
|
||||
- Check 2001/westley for making `main()` have two args. Easy to make it have two
|
||||
args but harder to make it function right.
|
||||
|
||||
- Check for video links in README.md files and see if the videos can be
|
||||
embedded into the README.md files themselves. An entry that the video file is
|
||||
downloaded already is 2006/sykes1. There are others that I need to look at once
|
||||
the rest of the entries are done, assuming that it's possible.
|
||||
Reference in new issue
Block a user