Add 2011/hou/try.sh + format/typo checks
This should complete 2011/hou's review.
This commit is contained in:
1 parent
d70df4a6a1
commit
b18d0c5fa8
3 files changed
+65
-11
No files matched your search
+14
-11
@@ -15,16 +15,11 @@ make
|
|||||||
### Try:
|
### Try:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./hou '11/26+222/31'
|
./try.sh
|
||||||
|
|
||||||
./hou 'log((21701-19937)-(23209-21701))/log(2)'
|
|
||||||
|
|
||||||
./hou 'sin(1.5708)+0.04321+log(sqrt(exp(1*1*1)))+(1+2*3)-0.4-0.6+(4+6)*(2-1+2*3)-tan(0.785398)+2*10/3*6*sqrt(16/2/2)*10+10000-1000'
|
|
||||||
|
|
||||||
./hou 'a calculator expression -- see the C Code for details'
|
|
||||||
```
|
```
|
||||||
|
|
||||||
What does the last one mean?
|
As the script asks you, what does the last one mean? Can you get it to report a
|
||||||
|
different value? Hint: it's in this file, kind of.
|
||||||
|
|
||||||
|
|
||||||
## Judges' remarks:
|
## Judges' remarks:
|
||||||
@@ -50,30 +45,36 @@ What does this evaluate to in C?
|
|||||||
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
|
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Self documenting source
|
### Self documenting source
|
||||||
|
|
||||||
Comments would almost be redundant. :-}
|
Comments would almost be redundant. :-}
|
||||||
|
|
||||||
|
|
||||||
### The ASCII art is valid C code
|
### The ASCII art is valid C code
|
||||||
|
|
||||||
... and not just fancy formatted comment removed by the C Pre-processor.
|
... and not just fancy formatted comment removed by the C Pre-processor.
|
||||||
|
|
||||||
|
|
||||||
### The only multi-byte strings are format strings
|
### The only multi-byte strings are format strings
|
||||||
|
|
||||||
The code does not contain some simple string-encoded lookup table for calculator
|
The code does not contain some simple string-encoded lookup table for calculator
|
||||||
operations.
|
operations.
|
||||||
|
|
||||||
|
|
||||||
### Example input and output in the source
|
### Example input and output in the source
|
||||||
|
|
||||||
The example input and output in the C code is significant. Can you find out
|
The example input and output in the C code is significant. Can you find out
|
||||||
why?
|
why?
|
||||||
|
|
||||||
|
|
||||||
### The button layout
|
### The button layout
|
||||||
|
|
||||||
The button layout in the C code is significant ... not just a nice looking
|
The button layout in the C code is significant ... not just a nice looking
|
||||||
layout.
|
layout.
|
||||||
|
|
||||||
### input parsing
|
|
||||||
|
### Input parsing
|
||||||
|
|
||||||
The parser is functionally equivalent to a normal arithmetic parser for all
|
The parser is functionally equivalent to a normal arithmetic parser for all
|
||||||
valid inputs. For another fun challenge: try to determine how it parses the
|
valid inputs. For another fun challenge: try to determine how it parses the
|
||||||
@@ -91,7 +92,7 @@ supported functionality using embedded ASCII art.
|
|||||||
- A few line numbers are significant and careless beautification will break the
|
- A few line numbers are significant and careless beautification will break the
|
||||||
program.
|
program.
|
||||||
- The entire ASCII art is valid code. The preprocessor won't remove any part of it.
|
- The entire ASCII art is valid code. The preprocessor won't remove any part of it.
|
||||||
- The only strings longer than 1 byte are printf/sscanf format strings, even
|
- The only strings longer than 1 byte are `printf(3)`/`sscanf(3)` format strings, even
|
||||||
after preprocessing. No string-encoded lookup table is used.
|
after preprocessing. No string-encoded lookup table is used.
|
||||||
- The example input and its expected output are both algorithmically
|
- The example input and its expected output are both algorithmically
|
||||||
significant.
|
significant.
|
||||||
@@ -99,14 +100,16 @@ significant.
|
|||||||
- The actual syntax being parsed is not that obvious, despite being functionally
|
- The actual syntax being parsed is not that obvious, despite being functionally
|
||||||
equivalent for all correct inputs.
|
equivalent for all correct inputs.
|
||||||
|
|
||||||
|
|
||||||
### Portability
|
### Portability
|
||||||
|
|
||||||
- This program requires `argv` to point to writable memory. It doesn't require
|
- This program requires `argv` to point to writable memory. It doesn't require
|
||||||
the actual argv strings to be writable, though.
|
the actual `argv` strings to be writable, though.
|
||||||
- This program requires ASCII.
|
- This program requires ASCII.
|
||||||
- This program doesn't work with `%e` style numbers like `1e-4`.
|
- This program doesn't work with `%e` style numbers like `1e-4`.
|
||||||
- Some seemingly redundant code works to eliminate warnings and evade a gcc bug.
|
- Some seemingly redundant code works to eliminate warnings and evade a gcc bug.
|
||||||
|
|
||||||
|
|
||||||
### Spoilers
|
### Spoilers
|
||||||
|
|
||||||
The parser parses function names, subtraction, and division as single-letter
|
The parser parses function names, subtraction, and division as single-letter
|
||||||
|
|||||||
Executable
+46
@@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# try.sh - demonstrate IOCCC winner 2011/hou
|
||||||
|
#
|
||||||
|
|
||||||
|
# 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 "Observe how this one is in the code, both the equation and the answer: "
|
||||||
|
echo "$ ./hou '11/26+222/31'" 1>&2
|
||||||
|
./hou '11/26+222/31'
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to continue: "
|
||||||
|
echo "$ ./hou 'log((21701-19937)-(23209-21701))/log(2)'" 1>&2
|
||||||
|
./hou 'log((21701-19937)-(23209-21701))/log(2)'
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to continue: "
|
||||||
|
echo "$ ./hou 'sin(1.5708)+0.04321+log(sqrt(exp(1*1*1)))+(1+2*3)-0.4-0.6+(4+6)*(2-1+2*3)-tan(0.785398)+2*10/3*6*sqrt(16/2/2)*10+10000-1000'" 1>&2
|
||||||
|
./hou 'sin(1.5708)+0.04321+log(sqrt(exp(1*1*1)))+(1+2*3)-0.4-0.6+(4+6)*(2-1+2*3)-tan(0.785398)+2*10/3*6*sqrt(16/2/2)*10+10000-1000'
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to continue: "
|
||||||
|
echo "$ ./hou '1+2*3'" 1>&2
|
||||||
|
./hou '1+2*3'
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to continue: "
|
||||||
|
echo "$ ./hou '(1+2)*3'" 1>&2
|
||||||
|
./hou '(1+2)*3'
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to continue: "
|
||||||
|
echo "$ ./hou 'a calculator expression -- see the C Code for details'" 1>&2
|
||||||
|
./hou 'a calculator expression -- see the C Code for details'
|
||||||
|
echo "Now answer: what does the last one mean? Can you get it to report something else?" 1>&2
|
||||||
@@ -3226,6 +3226,11 @@ and now it does work with 64-bit systems as well as 32-bit systems.
|
|||||||
Cody added the following words of wisdom: 'this is not a pipe'.
|
Cody added the following words of wisdom: 'this is not a pipe'.
|
||||||
|
|
||||||
|
|
||||||
|
## [2011/hou](2011/hou/hou.c) ([README.md](2011/hou/README.md]))
|
||||||
|
|
||||||
|
Cody added the [try.sh](2011/hou/try.sh) script.
|
||||||
|
|
||||||
|
|
||||||
## [2011/konno](2011/konno/konno.c) ([README.md](2011/konno/README.md]))
|
## [2011/konno](2011/konno/konno.c) ([README.md](2011/konno/README.md]))
|
||||||
|
|
||||||
Cody fixed the program to not crash if no arg was specified as this was not a
|
Cody fixed the program to not crash if no arg was specified as this was not a
|
||||||
|
|||||||
Reference in new issue
Block a user