Add 2011/blakely/try.sh + format/typo checks
This commit is contained in:
1 parent
30828808bc
commit
d4f267b60d
3 files changed
+76
-26
No files matched your search
+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
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user