Add 2014/endoh1/try.sh, fix rake.sh, format/typos

The rake.sh script had a typo where '1>&2' was just '1>2'.

The README.md and spoilers.md files were format and typo checked.

I believe this should complete 2014/endoh1.
This commit is contained in:
Cody Boone Ferguson committed 2023-12-05 11:14:24 -08:00
1 parent 4a946614e8
commit 539e1dce7f
5 files changed
+109 -48

No files matched your search

+13 -18
View File
@@ -15,25 +15,18 @@ make
### Try: ### Try:
```sh ```sh
./prog > main.c ./try.sh
make main
./main Hello
``` ```
Also try: The script will ask you if you wish to run `make rake` but this is not necessary
to fully enjoy the entry. `make rake` will run the [rake.sh](rake.sh) script and
```sh then `prog` if all is built okay. If `rake` is not installed then it will check
make rake 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
which will run the [rake.sh](rake.sh) script and then `prog` if all is built `gem` command as either root or via sudo and then to try running `make rake` or
okay. If `rake` is not installed then it will check that `gem` is installed. If `./rake.sh` again. If `rake` succeeds it will run `./prog` which can be used to
`gem` is not installed it will tell you where to get it and then tell you how to build `main.c`.
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`? What is the difference between running `./prog` and `main`?
@@ -64,9 +57,11 @@ more than 1000 words.
## Author's remarks: ## Author's remarks:
### Remarks ### Remarks
You may want to use a large display with a very small-font terminal. You may want to use a large display with a very small terminal font.
### Spoiler ### Spoiler
+1 -1
View File
@@ -20,7 +20,7 @@ if ! type -P rake >/dev/null 2>&1; then
else else
echo "Please run the following command as root or via sudo:" 1>&2 echo "Please run the following command as root or via sudo:" 1>&2
echo "" echo ""
echo " gem install rake" 1>2 echo " gem install rake" 1>&2
echo "" 1>&2 echo "" 1>&2
echo "and then try running make rake or running $0 again" 1>&2 echo "and then try running make rake or running $0 again" 1>&2
fi fi
+29 -20
View File
@@ -7,8 +7,8 @@ requires a bit stream, Reed-Solomon codes, BCH codes, data relocation, big (and
irregular!) numerical tables, human-oriented pattern arrangement (difficult to irregular!) numerical tables, human-oriented pattern arrangement (difficult to
implement by a small program), etc. implement by a small program), etc.
On the other hand, a quine has a big restriction: On the other hand, a quine has a big restriction: it needs to have two copies of
it needs to have two copies of the program! the program!
Do you think that it is possible to write QR code encoder in C within *1kB*? Do you think that it is possible to write QR code encoder in C within *1kB*?
@@ -18,7 +18,9 @@ Do you think that it is possible to write QR code encoder in C within *1kB*?
It is known that we can mitigate the quine restriction by `eval`. It is known that we can mitigate the quine restriction by `eval`.
For example, this is a quine written in Ruby: For example, this is a quine written in Ruby:
eval s="print 'eval s='; p s" ```ruby
eval s="print 'eval s='; p s"
```
Note that `print` appears just once in the program. Note that `print` appears just once in the program.
@@ -29,8 +31,10 @@ char s[]="<main code>int main() { <VM code> }";
int main() { <VM code>; } int main() { <VM code>; }
``` ```
* `<VM code>` : An own VM implementation (written in C) that executes the main code * `<VM code>` : An own VM implementation (written in C) that executes the main
* `<main code>` : An object code of quine and QR code encoder (written in the assembly language of the VM) 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) `<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! appears twice. So the whole code is about 1100 + 450 * 2 = 2000 bytes. Hooray!
@@ -45,7 +49,7 @@ code>` and `<VM code>`.
* 21 integer registers access * 21 integer registers access
* read, write, inc-and-read, dec-and-read * read, write, inc-and-read, dec-and-read
* Binary operations * Binary operations
* add, sub, mul, div, mod, xor, less than, equal, rshift * add, sub, mul, div, mod, xor, less than, equal, right shift
* Stack operation * Stack operation
* push (an immediate value) * push (an immediate value)
* Heap access * Heap access
@@ -55,10 +59,11 @@ code>` and `<VM code>`.
* Misc. * Misc.
* putchar, exit * putchar, exit
The instructions have variable length, but many of them are represented as one The instructions have variable lengths, but many of them are represented as one
printable character. (See `machine.rb` and `assemble.rb` in detail.) The printable character. (See [machine.rb](machine.rb) and
mapping between instructions and characters is also carefully designed to [assemble.rb](assemble.rb) in detail.) The mapping between instructions and
minimize `<VM code>`, which makes the resulted program non-human-readable. characters is also carefully designed to minimize `<VM code>`, which makes the
resulted program non-human-readable.
## How did I create the main code? ## How did I create the main code?
@@ -126,30 +131,34 @@ $ rake
I checked that the following QR code readers can read the output of my program. I checked that the following QR code readers can read the output of my program.
* Linux: [ZBar bar code reader][1] * 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 ### A note from the judges in 2023:
The author also tested an Android app called Barcode Scanner which used to be
found at found at
`https://play.google.com/store/apps/details?id=com.google.zxing.client.android` `https://play.google.com/store/apps/details?id=com.google.zxing.client.android`
but it appears to no longer exist. but it appears to no longer exist.
[1]: http://zbar.sourceforge.net/ [1]: http://zbar.sourceforge.net/
You can use `tool.rb` to convert the output to a png file. You can use [tool.rb](tool.rb) to convert the output to a png file.
$ ./main Hello | ruby tool.rb > hello.png ```sh
./main Hello | ruby tool.rb > hello.png
$ zbarimg -q hello.png $ zbarimg -q hello.png
QR-Code:Hello QR-Code:Hello
$ ruby tool.rb prog.c
$ ruby tool.rb prog.c | ruby tool.rb
```
$ ruby tool.rb prog.c
$ ruby tool.rb prog.c | ruby tool.rb
## Limitations ## Limitations
* QR code error correction level is fixed to L (Low). * QR code error correction level is fixed to L (Low).
* It supports only byte mode (not numeric, alphanumeric, kanji mode...) * It supports only byte mode (not numeric, alphanumeric, kanji mode...).
* The mask pattern is fixed to 4. * The mask pattern is fixed to 4.
* The mask is not applied to the remained bits. * The mask is not applied to the remained bits.
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 2014/endoh1
#
# 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 show prog.c (space = next page, q = quit): "
echo 1>&2
less -EXF prog.c
echo 1>&2
read -r -n 1 -p "Press any key to run: ./prog: "
echo 1>&2
./prog
echo 1>&2
read -r -n 1 -p "Press any key to run: ./prog > main.c: "
echo 1>&2
./prog > main.c
read -r -n 1 -p "Press any key to run: make main: "
echo 1>&2
make main
read -r -n 1 -p "Press any key to run: ./main IOCCC: "
echo 1>&2
./main IOCCC
echo 1>&2
read -r -n 1 -p "Press any key to run: ./main Hello: "
echo 1>&2
./main Hello
echo 1>&2
read -r -n 1 -p "Press any key to run: ./prog IOCCC: "
echo 1>&2
./prog IOCCC
echo 1>&2
read -r -p "Do you want to run make rake (Y/N)? "
if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then
make rake 2>/dev/null
fi
+12 -9
View File
@@ -3688,18 +3688,21 @@ that was fixed and it also has `#include <stdio.h>` for `putchar(3)`. The
## [2014/endoh1](2014/endoh1/prog.c) ([README.md](2014/endoh1/README.md])) ## [2014/endoh1](2014/endoh1/prog.c) ([README.md](2014/endoh1/README.md]))
[Cody](#cody) added the [rake.sh](2014/endoh1/rake.sh) script and `make rake` rule that [Cody](#cody) added the [rake.sh](2014/endoh1/rake.sh) script and `make rake`
runs the script. This script will check that `rake` is installed and if it is rule that runs the script. This script will check that `rake` is installed and
not it will report this and then check that `gem` is installed. It checks that if it is not it will report this and then check that `gem` is installed. It
`gem` is installed in this case because `gem` is how you install `rake`. If checks that `gem` is installed in this case because `gem` is how you install
`gem` is not installed it tells you to get it along with how to install `gem`. `rake`. If `gem` is not installed it tells you to get it along with how to
Then it tells you how to install `rake`. If `rake` fails to run then it tells install `gem`. Then it tells you how to install `rake`. If `rake` fails to run
you to install a specific gem and then to try again. Finally if `rake` succeeds then it tells you to install a specific gem and then to try again. Finally if
it will verify that `prog` is executable and if it is it will run it. `rake` succeeds it will verify that `prog` is executable and if it is it will
run it.
Cody also added the [try.sh](2014/endoh1/try.sh) script.
**_Barely_** worth noting but done nonetheless, Cody renamed the `read_me.md` **_Barely_** worth noting but done nonetheless, Cody renamed the `read_me.md`
file to [spoilers.md](2014/endoh1/spoilers.md) to be clearer in its purpose as file to [spoilers.md](2014/endoh1/spoilers.md) to be clearer in its purpose as
it is a file with spoilers. it is a file with spoilers (and too close to README.md?).
## [2014/maffiodo1](2014/maffiodo1/prog.c) ([README.md](2014/maffiodo1/README.md])) ## [2014/maffiodo1](2014/maffiodo1/prog.c) ([README.md](2014/maffiodo1/README.md]))