Format fix and other updates to 2014/endoh1

Add make rake and rake.sh script that runs the rake command and then
runs prog (if all okay). If rake is not installed it reports this and
checks that gem is installed (as gem installs rake) and if gem is not
installed it reports that and tells one how to get it and what to run
after that. If rake is not installed and gem is it tells the user what
to do as well. After this it tells the user to run the rule or rake.sh
again. If rake is installed but it fails to work it suggests to install
a specific gem (that the author noted in the spoilers file) and then
trying again. An important note on the check for gem is it does not tell
one how to install it but rather use it so if it's run again and for
some reason rake is not installed then it will report the same issue
again. The reason it is done this way is because the ruby file the
README.md file suggests to be executed has an error in it, at least in
macOS. This script should in any event simplify the usage of the entry.

The read_me.md file was renamed to spoilers.md to be clearer in purpose:
it contains spoilers and just having it be read_me.md is not clear.

Updated the todo: now entries up through all of 2013 and up through
2014/endoh1 have had the first pass of the README.md files: the format
fixes. These files will have to be typo checked next. Also
YYYY/README.md files have been checked through 2001 with the caveat that
some changes have to be done with them namely to do with email addresses
(and UUCP addresses) that no longer exist. These things are now noted
and it's noted that format fixes is a prerequisite of typo checks.
This commit is contained in:
Cody Boone Ferguson committed 2023-10-16 04:33:57 -07:00
1 parent 7f28d5586c
commit b032564f30
9 files changed
+278 -166

No files matched your search

+8
View File
@@ -4,3 +4,11 @@ prog
treacle
treacle.c
prog.orig
m.c
src/
src.zip
seq.txt
alpha.txt
ast.txt
reg.txt
raw.txt
+3
View File
@@ -139,6 +139,9 @@ main.c: prog
${RM} -f $@
./${PROG} > $@
rake: Rakefile rake.sh
@./rake.sh
# alternative executable
#
alt: data ${ALT_TARGET}
+31 -5
View File
@@ -1,8 +1,9 @@
# Most square (YODA award)
Yusuke Endoh
<mame@ruby-lang.org>
<https://github.com/mame/>
Yusuke Endoh<br>
<mame@ruby-lang.org><br>
<https://github.com/mame/>
Mastodon: [@mame@ruby.social](https://ruby.social/@mame)
## To build:
@@ -25,18 +26,43 @@ make main
./main Hello
```
Also try:
```sh
make rake
```
which will run the [rake.sh](rake.sh) script and then `prog` if all is built
okay. If `rake` is not installed then it will check that `gem` is installed. If
`gem` is not installed it will tell you where to get it and then tell you how to
install `rake`. Otherwise, if `rake` is installed it will try running `rake `
and if that fails to run it will tell you to run a `gem` command as either root
or via sudo and then to try running `make rake` or `./rake.sh` again. If `rake`
succeeds it will run `./prog` which can be used to build `main.c`.
What is the difference between running `./prog` and `main`?
## Judges' remarks:
Big terminals with tiny fonts have their uses in certain cases.
One of them is:
```sh
make treacl
./treacl
```
which is shorthand for:
```sh
./prog < prog.c > treacle.c
make treacle
./treacle
```
When using a smart phone to read the output, you may need to
When using a smartphone to read the output, you may need to
step back to see the bigger picture because that picture is worth
more than 1000 words.
@@ -48,7 +74,7 @@ You may want to use a large display with a very small-font terminal.
### Spoiler
Decompress `src.zip` if you need explanation.
See [spoilers.md](spoilers.md).
## Copyright and CC BY-SA 4.0 License:
+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
if ! type -P rake >/dev/null 2>&1; then
echo "'rake' cannot be found." 1>&2
echo "'rake' must be installed to run make rake or $0." 1>&2
echo "" 1>&2
if ! type -P gem >/dev/null 2>&1; then
echo "" 1>&2
echo "'gem' cannot be found." 1>&2
echo "To install 'rake' you will need the 'gem' tool." 1>&2
echo "Please see the following GitHub repo for rubygems:" 1>&2
echo "" 1>&2
echo " https://github.com/rubygems/rubygems" 1>&2
echo "" 1>&2
echo "and then run:" 1>&2
echo "" 1>&2
echo " cd rubygems && exe/gem install rake" 1>&2
echo "" 1>&2
echo "and then try running make rake or running $0 again." 1>&2
else
echo "Please run the following command as root or via sudo:" 1>&2
echo ""
echo " gem install rake" 1>2
echo "" 1>&2
echo "and then try running make rake or running $0 again" 1>&2
fi
exit 1
elif ! rake 2>&1; then
echo "" 1>&2
echo "It appears that using rake failed. Please try running the following" 1>&2
echo "command as root or via sudo: " 1>&2
echo "" 1>&2
echo " gem install ruby-minisat" 1>&2;
echo "" 1>&2
echo "and then try running make rake or $0 again" 1>&2
exit 1
elif [[ ! -x prog ]]; then
echo "" 1>&2
echo "could not compile prog" 1>&2
exit 1
else
./prog 1>&2
exit "$?"
fi
-149
View File
@@ -1,149 +0,0 @@
# Q(uine)R code generator
## What is difficult?
As you may know, QR code (specification: ISO/IEC 18004) is quite complex.
It requires a bit stream, Reed-Solomon codes, BCH codes,
data relocation, big (and irregular!) numerical tables,
human-oriented pattern arrangement (difficult to implement by a small program),
etc.
On the other hand, a quine has a big restriction:
it needs to have two copies of the program!
Do you think that it is possible to write QR code encoder in C within *1kB*?
## How did I achieve that?
It is known that we can mitigate the quine restriction by `eval`.
For example, this is a quine written in Ruby:
eval s="print 'eval s='; p s"
Note that `print` appears just once in the program.
To emulate this approach in C, I adopted the following structure.
char s[]="<main code>int main() { <VM code> }";
int main() { <VM code>; }
* `<VM code>` : An own VM implementation (written in C) that executes the main code
* `<main code>` : An object code of quine and QR code encoder (written in the assembly language of the VM)
`<main code>` (about 1100 bytes) appears once
and `<VM code>` (about 450 bytes) appears twice.
So the whole code is about 1100 + 450 * 2 = 2000 bytes. Hooray!
## What sort of VM is that?
The VM is a kind of stack machine which makes the object code compact.
The instruction set is carefully selected
to minimize the sizes of both `<main code>` and `<VM code>`.
* 21 integer registers access
* read, write, inc-and-read, dec-and-read
* Binary operations
* add, sub, mul, div, mod, xor, less than, equal, rshift
* Stack operation
* push (an immediate value)
* Heap access
* load, store
* If-Then-Else
* While-Loop
* Misc.
* putchar, exit
The instructions have variable length,
but many of them are represented as one printable character.
(See `machine.rb` and `assemble.rb` in detail.)
The mapping between instructions and characters is also carefully designed
to minimize `<VM code>`,
which makes the resulted program non-human-readable.
## How did I create the main code?
It is too tedious to write the machine language directly.
So I wrote the source code in Ruby syntax and created a Ruby-to-VM compiler
that involves alpha renaming and automatic register allocation
only for this purpose.
* `src.rb`: the source code of QR code encoder written in Ruby syntax.
* `vm.c`: the source code of the VM.
The compiler tool chain is the following.
src.rb interp.c
| |
| [parse.rb] |
V |
ast.txt |
| |
| [serialize.rb] |
V |
seq.txt |
| |
| [alpha.rb] |
V |
alpha.txt |
| |
| [register.rb] |
V |
reg.txt |
| |
| [assemble.rb] |
V |
raw.txt |
| |
+---------+---------+
|
| [link.rb]
V
main.c
|
| [gen-prog.c]
V
prog.c
* `parse.rb` converts Ruby to AST.
* `serialize.rb` converts AST to intermediate instruction sequence.
* `alpha.rb` applies "alpha-renaming" to the instruction sequence.
* `register.rb` applies "register allocation".
* `assemble.rb` converts the sequence to the final stack-machine instructions.
* `interp.c` is an implementation of the VM.
* `link.rb` generates `main.c` by linking the instructions and interpreter source.
* `gen-prog.c` generates `prog.c` based on `main.c`
You can run the process by `rake` command. `ruby-minisat` gem is needed.
$ gem install ruby-minisat
$ rake
## Tools
I checked that the following QR code readers can read the output of my program.
* Linux: [ZBar bar code reader][1]
* Android: [Barcode Scanner][2]
[1]: http://zbar.sourceforge.net/
[2]: https://play.google.com/store/apps/details?id=com.google.zxing.client.android]
You can use `tool.rb` to convert the output to a png file.
$ ./main Hello | ruby tool.rb > hello.png
$ zbarimg -q hello.png
QR-Code:Hello
$ ruby tool.rb prog.c
$ ruby tool.rb prog.c | ruby tool.rb
## Limitations
* QR code error correction level is fixed to L (Low).
* It supports only byte mode (not numeric, alphanumeric, kanji mode...)
* The mask pattern is fixed to 4.
* The mask is not applied to the remained bits.
+155
View File
@@ -0,0 +1,155 @@
# Q(uine)R code generator
## What is difficult?
As you may know, QR code (specification: ISO/IEC 18004) is quite complex. It
requires a bit stream, Reed-Solomon codes, BCH codes, data relocation, big (and
irregular!) numerical tables, human-oriented pattern arrangement (difficult to
implement by a small program), etc.
On the other hand, a quine has a big restriction:
it needs to have two copies of the program!
Do you think that it is possible to write QR code encoder in C within *1kB*?
## How did I achieve that?
It is known that we can mitigate the quine restriction by `eval`.
For example, this is a quine written in Ruby:
eval s="print 'eval s='; p s"
Note that `print` appears just once in the program.
To emulate this approach in C, I adopted the following structure.
```
char s[]="<main code>int main() { <VM code> }";
int main() { <VM code>; }
```
* `<VM code>` : An own VM implementation (written in C) that executes the main code
* `<main code>` : An object code of quine and QR code encoder (written in the assembly language of the VM)
`<main code>` (about 1100 bytes) appears once and `<VM code>` (about 450 bytes)
appears twice. So the whole code is about 1100 + 450 * 2 = 2000 bytes. Hooray!
## What sort of VM is that?
The VM is a kind of stack machine which makes the object code compact. The
instruction set is carefully selected to minimize the sizes of both `<main
code>` and `<VM code>`.
* 21 integer registers access
* read, write, inc-and-read, dec-and-read
* Binary operations
* add, sub, mul, div, mod, xor, less than, equal, rshift
* Stack operation
* push (an immediate value)
* Heap access
* load, store
* If-Then-Else
* While-Loop
* Misc.
* putchar, exit
The instructions have variable length, but many of them are represented as one
printable character. (See `machine.rb` and `assemble.rb` in detail.) The
mapping between instructions and characters is also carefully designed to
minimize `<VM code>`, which makes the resulted program non-human-readable.
## How did I create the main code?
It is too tedious to write the machine language directly. So I wrote the source
code in Ruby syntax and created a Ruby-to-VM compiler that involves alpha
renaming and automatic register allocation only for this purpose.
* [src.rb](src.rb): the source code of QR code encoder written in Ruby syntax.
* [vm.c](vm.c): the source code of the VM.
The compiler tool chain is the following.
```
src.rb interp.c
| |
| [parse.rb] |
V |
ast.txt |
| |
| [serialize.rb] |
V |
seq.txt |
| |
| [alpha.rb] |
V |
alpha.txt |
| |
| [register.rb] |
V |
reg.txt |
| |
| [assemble.rb] |
V |
raw.txt |
| |
+---------+---------+
|
| [link.rb]
V
main.c
|
| [gen-prog.c]
V
prog.c
```
* [parse.rb](parse.rb) converts Ruby to AST.
* [serialize.rb](serialize.rb) converts AST to intermediate instruction sequence.
* [alpha.rb](alpha.rb) applies "alpha-renaming" to the instruction sequence.
* [register.rb](register.rb) applies "register allocation".
* [assemble.rb](assemble.rb) converts the sequence to the final stack-machine instructions.
* [interp.c](interp.c) is an implementation of the VM.
* [link.rb](link.rb) generates `main.c` by linking the instructions and interpreter source.
* [gen-prog.c](gen-prog.c) generates [prog.c](prog.c) based on `main.c`.
You can run the process by `rake` command. `ruby-minisat` gem is needed.
```sh
$ gem install ruby-minisat
$ rake
```
## Tools
I checked that the following QR code readers can read the output of my program.
* Linux: [ZBar bar code reader][1]
### 2023 note from the judges:
The author also tested an Android app called Barcode Scanner] which used to be
found at
`https://play.google.com/store/apps/details?id=com.google.zxing.client.android`
but it appears to no longer exist.
[1]: http://zbar.sourceforge.net/
You can use `tool.rb` to convert the output to a png file.
$ ./main Hello | ruby tool.rb > hello.png
$ zbarimg -q hello.png
QR-Code:Hello
$ ruby tool.rb prog.c
$ ruby tool.rb prog.c | ruby tool.rb
## Limitations
* QR code error correction level is fixed to L (Low).
* It supports only byte mode (not numeric, alphanumeric, kanji mode...)
* The mask pattern is fixed to 4.
* The mask is not applied to the remained bits.
+4 -3
View File
@@ -1,8 +1,9 @@
# Best use of bioinformatics
Yusuke Endoh
<mame@ruby-lang.org>
<https://github.com/mame/>
Yusuke Endoh<br>
<mame@ruby-lang.org><br>
<https://github.com/mame/><br>
Mastodon: [@mame@ruby.social](https://ruby.social/@mame)
## To build: