From 539e1dce7fed2b0322a5a4d0077f757fad624e33 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:14:24 -0800 Subject: [PATCH] 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. --- 2014/endoh1/README.md | 31 ++++++++++------------- 2014/endoh1/rake.sh | 2 +- 2014/endoh1/spoilers.md | 49 ++++++++++++++++++++++--------------- 2014/endoh1/try.sh | 54 +++++++++++++++++++++++++++++++++++++++++ thanks-for-fixes.md | 21 +++++++++------- 5 files changed, 109 insertions(+), 48 deletions(-) create mode 100755 2014/endoh1/try.sh diff --git a/2014/endoh1/README.md b/2014/endoh1/README.md index 5deec88d5..26ed90586 100644 --- a/2014/endoh1/README.md +++ b/2014/endoh1/README.md @@ -15,25 +15,18 @@ make ### Try: ```sh -./prog > main.c - -make main -./main Hello +./try.sh ``` -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`. +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 +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`? @@ -64,9 +57,11 @@ more than 1000 words. ## Author's 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 diff --git a/2014/endoh1/rake.sh b/2014/endoh1/rake.sh index 0a599718d..7658bde56 100755 --- a/2014/endoh1/rake.sh +++ b/2014/endoh1/rake.sh @@ -20,7 +20,7 @@ if ! type -P rake >/dev/null 2>&1; then else echo "Please run the following command as root or via sudo:" 1>&2 echo "" - echo " gem install rake" 1>2 + echo " gem install rake" 1>&2 echo "" 1>&2 echo "and then try running make rake or running $0 again" 1>&2 fi diff --git a/2014/endoh1/spoilers.md b/2014/endoh1/spoilers.md index 87bab360f..6d05f4e86 100644 --- a/2014/endoh1/spoilers.md +++ b/2014/endoh1/spoilers.md @@ -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 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! +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*? @@ -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`. 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. @@ -29,8 +31,10 @@ char s[]="
int main() { }"; int main() { ; } ``` -* `` : An own VM implementation (written in C) that executes the main code -* `
` : An object code of quine and QR code encoder (written in the assembly language of the VM) +* `` : An own VM implementation (written in C) that executes the main +code. +* `
` : An object code of quine and QR code encoder (written in the +assembly language of the VM). `
` (about 1100 bytes) appears once and `` (about 450 bytes) appears twice. So the whole code is about 1100 + 450 * 2 = 2000 bytes. Hooray! @@ -45,7 +49,7 @@ code>` and ``. * 21 integer registers access * read, write, inc-and-read, dec-and-read * 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 * push (an immediate value) * Heap access @@ -55,10 +59,11 @@ code>` and ``. * 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 ``, which makes the resulted program non-human-readable. +The instructions have variable lengths, but many of them are represented as one +printable character. (See [machine.rb](machine.rb) and +[assemble.rb](assemble.rb) in detail.) The mapping between instructions and +characters is also carefully designed to minimize ``, which makes the +resulted program non-human-readable. ## 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. -* 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 `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. +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 - QR-Code:Hello +$ zbarimg -q hello.png +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 * 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 is not applied to the remained bits. diff --git a/2014/endoh1/try.sh b/2014/endoh1/try.sh new file mode 100755 index 000000000..a8fdc6a43 --- /dev/null +++ b/2014/endoh1/try.sh @@ -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 diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 797dece68..fc2dbae05 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3688,18 +3688,21 @@ that was fixed and it also has `#include ` for `putchar(3)`. The ## [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 -runs the script. This script will check that `rake` is installed and if it is -not it will report this and then check that `gem` is installed. It checks that -`gem` is installed in this case because `gem` is how you install `rake`. If -`gem` is not installed it tells you to get it along with how to install `gem`. -Then it tells you how to install `rake`. If `rake` fails to run then it tells -you to install a specific gem and then to try again. Finally if `rake` succeeds -it will verify that `prog` is executable and if it is it will run it. +[Cody](#cody) added the [rake.sh](2014/endoh1/rake.sh) script and `make rake` +rule that runs the script. This script will check that `rake` is installed and +if it is not it will report this and then check that `gem` is installed. It +checks that `gem` is installed in this case because `gem` is how you install +`rake`. If `gem` is not installed it tells you to get it along with how to +install `gem`. Then it tells you how to install `rake`. If `rake` fails to run +then it tells you to install a specific gem and then to try again. Finally if +`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` 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]))