Merge pull request #1649 from xexyl/muth2015-try
This commit is contained in:
5 files changed
+175
-45
No files matched your search
+31
-22
@@ -15,13 +15,7 @@ make -B [MACHINE=your_machine.h] [TAPE=your_tape.h] [X=[0|1|2|3|4|5|6|7|8|9]] [V
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
make -B V=2 run
|
||||
|
||||
strings prog | grep '(,)'
|
||||
|
||||
make -B MACHINE=machine_times2.h TAPE=tape_five.h V=1 run
|
||||
|
||||
make -B MACHINE=machine_chaos_5_2.h X=5 run
|
||||
./try.sh
|
||||
```
|
||||
|
||||
|
||||
@@ -51,21 +45,28 @@ even without conditionals and recursive file inclusion as some kind of a
|
||||
- make target `run` runs `./prog` and filters a little statistics out of the verbose output
|
||||
- `X` (defaults to 3) sets the maximum number of steps: *M*(`X`) ~ 8<sup>`X`</sup>
|
||||
|
||||
|
||||
### Limitations
|
||||
|
||||
If the machine does not halt after *M*(`X`) steps, you will see unexpanded macros in the output.
|
||||
If the machine does not halt after *M*(`X`) steps, you will see unexpanded
|
||||
macros in the output.
|
||||
|
||||
|
||||
### Compiler warnings
|
||||
|
||||
If `V=1` or `V=2` is used, you may see "`warning: string length is greater than the length '4095' ISO C99 compilers are required to support`".
|
||||
If `V=1` or `V=2` is used, you may see "`warning: string length is greater than
|
||||
the length '4095' ISO C99 compilers are required to support`".
|
||||
|
||||
|
||||
### Programming
|
||||
|
||||
Implementing your own Turing machine is easy. Take a look at the supplied header files for examples.
|
||||
Implementing your own Turing machine is easy. Take a look at the supplied header
|
||||
files for examples.
|
||||
|
||||
|
||||
#### Tape Symbols
|
||||
|
||||
Every symbol used (except "`_`") must be explicitly declared using
|
||||
Every symbol used (except `_`) must be explicitly declared using
|
||||
|
||||
```c
|
||||
#define sym_SYMBOL(sym, _SYMBOL) sym
|
||||
@@ -77,9 +78,11 @@ Example:
|
||||
#define sym_1(sym, _1) sym
|
||||
```
|
||||
|
||||
|
||||
#### Tape
|
||||
|
||||
The initial content of the tape must be defined in the tape header using a triple like:
|
||||
The initial content of the tape must be defined in the tape header using a
|
||||
triple like:
|
||||
|
||||
```c
|
||||
#define tape ((((,),...l2), l1), c, (r1, (r2..., (,))))
|
||||
@@ -89,26 +92,32 @@ The initial content of the tape must be defined in the tape header using a tripl
|
||||
- `c` is the symbol at the current position
|
||||
- `r1`, `r2`, ... are the symbols to the right
|
||||
|
||||
The empty pairs "`(,)`" represent the continuations of the tape, filled with underscore symbols ("`_`"). They are expanded on demand.
|
||||
The empty pairs `(,)` represent the continuations of the tape, filled with
|
||||
underscore symbols (`_`). They are expanded on demand.
|
||||
|
||||
|
||||
#### State Machine
|
||||
|
||||
All transitions are defined in the machine header using the syntax
|
||||
|
||||
#define CURRENT_SCANNED (WRITE, MOVEMENT, NEXT)
|
||||
```
|
||||
#define CURRENT_SCANNED (WRITE, MOVEMENT, NEXT)
|
||||
```
|
||||
|
||||
where
|
||||
|
||||
- `CURRENT` is the current state
|
||||
- `SCANNED` is the symbol at the current position
|
||||
- the whitespace before the parentheses is significant
|
||||
- `WRITE` is the symbol to be written to the tape
|
||||
- `MOVEMENT` is "`L`" for left, "`R`" for right, or nothing
|
||||
- `NEXT` is the next state
|
||||
- `CURRENT` is the current state.
|
||||
- `SCANNED` is the symbol at the current position.
|
||||
- The whitespace before the parentheses is significant.
|
||||
- `WRITE` is the symbol to be written to the tape.
|
||||
- `MOVEMENT` is `L` for left, `R` for right; don't specify anything if you
|
||||
want no movement.
|
||||
- `NEXT` is the next state.
|
||||
|
||||
There must be a state "`A`" defined, which becomes the initial state of the machine.
|
||||
There must be a state `A` defined, which becomes the initial state of the
|
||||
machine.
|
||||
|
||||
To halt the machine, use the keyword "`break`" as in
|
||||
To halt the machine, use the keyword `break` as in
|
||||
|
||||
```c
|
||||
#define A_1 (2, break)
|
||||
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 2015/muth
|
||||
#
|
||||
|
||||
# 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 "$ make -B V=2 run" 1>&2
|
||||
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
|
||||
echo 1>&2
|
||||
make CC="${CC}" -B V=2 run | less -EXF
|
||||
echo 1>&2
|
||||
echo 1>&2
|
||||
|
||||
echo "$ strings prog | grep '(,)'" 1>&2
|
||||
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
|
||||
echo 1>&2
|
||||
strings prog | grep '(,)' | less -EXF
|
||||
echo 1>&2
|
||||
echo 1>&2
|
||||
|
||||
for h in machine*.h; do
|
||||
for t in tape*.h; do
|
||||
echo "$ make CC=\"\${CC}\" -B MACHINE=$h TAPE=$t V=1 run" 1>&2
|
||||
read -r -n 1 -p "Press any key to continue (q to exit): "
|
||||
if [[ "$REPLY" == "q" || "$REPLY" == "Q" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
echo 1>&2
|
||||
make -B MACHINE="$h" TAPE="$t" V=1 run
|
||||
echo 1>&2
|
||||
echo 1>&2
|
||||
done
|
||||
done
|
||||
|
||||
+6
-23
@@ -8,35 +8,16 @@ make
|
||||
## To use:
|
||||
|
||||
```sh
|
||||
echo Some text | ./prog\
|
||||
echo Some text | ./prog
|
||||
```
|
||||
|
||||
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
echo IOCCC 2015 | ./prog | tee output.c
|
||||
make output
|
||||
./output
|
||||
|
||||
echo IOCCC 2015 | ./prog_c11 | tee output.c
|
||||
make output
|
||||
./output
|
||||
|
||||
echo IOCCC 2015 | ./prog_c++98 | tee output.c
|
||||
make output
|
||||
./output
|
||||
./try.sh
|
||||
```
|
||||
|
||||
### Also try:
|
||||
|
||||
```sh
|
||||
./prog
|
||||
|
||||
```
|
||||
|
||||
Keep pressing enter to see more output. Send EOF to terminate.
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
@@ -54,7 +35,7 @@ so you need not worry about this.
|
||||
## Author's remarks:
|
||||
|
||||
`Fuuko` is a [sea star](https://en.wikipedia.org/wiki/Starfish) generator. Feed
|
||||
her some input through `stdin` to get lots of sea star patterns in `stdout`.
|
||||
her some input through `stdin` to get lots of sea star patterns on `stdout`.
|
||||
|
||||
```sh
|
||||
cc -O3 -std=c90 fuuko.c -lm -o fuuko_c90
|
||||
@@ -70,7 +51,7 @@ echo IOCCC | ./fuuko_c99 > output_c99.c
|
||||
```
|
||||
|
||||
Don't like [sea stars](https://en.wikipedia.org/wiki/Starfish)? Use a C++98
|
||||
compiler to get [dango](https://en.wikipedia.org/wiki/Dango) instead.
|
||||
compiler to get a [dango](https://en.wikipedia.org/wiki/Dango) instead.
|
||||
|
||||
```sh
|
||||
g++ -O3 -std=c++98 fuuko.c -lm -o fuuko_cpp98
|
||||
@@ -102,6 +83,7 @@ filled with pointer dereferences (C stars).
|
||||
Next time people ask you for a few pointers on C, you can run their
|
||||
question through `Fuuko` and give them pointers all day long.
|
||||
|
||||
|
||||
### Compatibility
|
||||
|
||||
`Fuuko` has been tested under these environments:
|
||||
@@ -117,6 +99,7 @@ question through `Fuuko` and give them pointers all day long.
|
||||
- clang 3.4.1 on Linux
|
||||
- tcc 0.9.25 on JS/Linux (C99 only)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
The most obscure parts are in detecting the subtle differences in
|
||||
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# try.sh - demonstrate IOCCC winner 2015/yang
|
||||
#
|
||||
|
||||
# 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" everything >/dev/null || exit 1
|
||||
|
||||
# clear screen after compilation so that only the entry is shown
|
||||
clear
|
||||
|
||||
|
||||
echo "$ echo IOCCC 2015 | ./prog | tee output.c | less" 1>&2
|
||||
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
|
||||
echo 1>&2
|
||||
echo IOCCC 2015 | ./prog | tee output.c | less -EXF
|
||||
echo "$ make CC=\"${CC}\" output" 1>&2
|
||||
make CC="${CC}" output 2>/dev/null
|
||||
read -r -n 1 -p "Press any key to run: ./output: "
|
||||
echo 1>&2
|
||||
./output
|
||||
|
||||
echo 1>&2
|
||||
echo "$ echo IOCCC 2015 | ./prog_c90 | tee output.c | less" 1>&2
|
||||
read -r -n 1 -p "Press any key to show sea star (space = next page, q = quit): "
|
||||
echo 1>&2
|
||||
echo IOCCC 2015 | ./prog_c90 | tee output.c | less -EXF
|
||||
echo "$ make CC=\"${CC}\" output" 1>&2
|
||||
make CC="${CC}" output 2>/dev/null
|
||||
read -r -n 1 -p "Press any key to run: ./output: "
|
||||
echo 1>&2
|
||||
./output
|
||||
|
||||
echo 1>&2
|
||||
echo "$ echo IOCCC 2015 | ./prog_c99 | tee output.c | less" 1>&2
|
||||
read -r -n 1 -p "Press any key to show sea star with eyes (space = next page, q = quit): "
|
||||
echo 1>&2
|
||||
echo IOCCC 2015 | ./prog_c99 | tee output.c | less -EXF
|
||||
echo "Did you notice the 'rabbit' in there?" 1>&2
|
||||
read -r -n 1 -p "Press any key to continue: "
|
||||
echo 1>&2
|
||||
echo "$ make CC=\"${CC}\" output" 1>&2
|
||||
make CC="${CC}" output 2>/dev/null
|
||||
read -r -n 1 -p "Press any key to run: ./output: "
|
||||
echo 1>&2
|
||||
./output
|
||||
|
||||
echo "$ echo IOCCC 2015 | ./prog_cpp98 | tee output.c | less" 1>&2
|
||||
read -r -n 1 -p "Press any key to show dango (space = next page, q = quit): "
|
||||
echo IOCCC 2015 | ./prog_cpp98 | tee output.c | less -EXF
|
||||
echo "$ make CC=\"${CC}\" output" 1>&2
|
||||
make CC="${CC}" output 2>/dev/null
|
||||
read -r -n 1 -p "Press any key to run: ./output: "
|
||||
echo 1>&2
|
||||
./output
|
||||
|
||||
echo "$ echo IOCCC 2015 | ./prog_cpp11 | tee output.c | less" 1>&2
|
||||
read -r -n 1 -p "Press any key to show circles/Swiss cheese (space = next page, q = quit): "
|
||||
echo IOCCC 2015 | ./prog_cpp11 | tee output.c | less -EXF
|
||||
echo "$ make CC=\"${CC}\" output" 1>&2
|
||||
make CC="${CC}" output 2>/dev/null
|
||||
read -r -n 1 -p "Press any key to run: ./output: "
|
||||
echo 1>&2
|
||||
./output
|
||||
|
||||
echo 1>&2
|
||||
echo "$ echo IOCCC 2015 | ./prog_c11 | tee output.c | less" 1>&2
|
||||
read -r -n 1 -p "Press any key to show no extra pattern (space = next page, q = quit): "
|
||||
echo 1>&2
|
||||
echo IOCCC 2015 | ./prog_c11 | tee output.c | less -EXF
|
||||
echo "$ make CC=\"${CC}\" output" 1>&2
|
||||
make CC="${CC}" output 2>/dev/null
|
||||
read -r -n 1 -p "Press any key to run: ./output: "
|
||||
echo 1>&2
|
||||
./output
|
||||
|
||||
read -r -n 1 -p "Press enter key repeatedly to get more output (send EOF to quit): "
|
||||
./prog
|
||||
exit 0
|
||||
@@ -3803,6 +3803,11 @@ simply typing `make back_to` or `make mullender`.
|
||||
(Linux doesn't seem to but macOS does).
|
||||
|
||||
|
||||
## [2015/muth](2015/muth/prog.c) ([README.md](2015/muth/README.md))
|
||||
|
||||
[Cody](#cody) added the [try.sh](2015/muth/try.sh) script.
|
||||
|
||||
|
||||
## [2015/yang](2015/yang/prog.c) ([README.md](2015/yang/README.md]))
|
||||
|
||||
[Cody](#cody) fixed an unfortunate typo in the Makefile that was preventing some of the
|
||||
@@ -3811,6 +3816,8 @@ files from compiling properly, trying instead to compile already compiled code.
|
||||
He also added explicit linking of libm (`-lm`) for systems that do not do this
|
||||
(Linux seems to not but macOS does).
|
||||
|
||||
He also added the [try.sh](2015/yang/try.sh) script.
|
||||
|
||||
|
||||
# <a name="2018"></a>2018
|
||||
|
||||
|
||||
Reference in new issue
Block a user