Format/typo check 2012/kang + update try.sh
This commit is contained in:
1 parent
a84d3f9d3f
commit
d7e73b4f38
2 files changed
+35
-29
No files matched your search
+27
-24
@@ -5,7 +5,7 @@ make
|
|||||||
```
|
```
|
||||||
|
|
||||||
There is alternate code which fixes some German at the expense of other German.
|
There is alternate code which fixes some German at the expense of other German.
|
||||||
See [Alternate code](#alternate-code) below.
|
See [Alternate code](#alternate-code) below for the (fun) rationale here.
|
||||||
|
|
||||||
|
|
||||||
## To use:
|
## To use:
|
||||||
@@ -35,8 +35,8 @@ This alternate code fixes the program that would throw off those who know German
|
|||||||
where the sound of 'V' is 'F' and so the program had the letter be 'F'. A
|
where the sound of 'V' is 'F' and so the program had the letter be 'F'. A
|
||||||
problem, however, with changing it is that it breaks other words including in
|
problem, however, with changing it is that it breaks other words including in
|
||||||
German. Thus there is the alternate version instead which fixes a problem for
|
German. Thus there is the alternate version instead which fixes a problem for
|
||||||
Germans that causes other problems for Germans so if you're German you'll just
|
Germans that causes problems for Germans so if you're German you'll just have to
|
||||||
have to deal with it :-) It is, however, good as you can appreciate the entry
|
deal with it :-) It is, however, good as you might be able appreciate the entry
|
||||||
even more.
|
even more.
|
||||||
|
|
||||||
|
|
||||||
@@ -107,10 +107,10 @@ It accepts a variety of spelt numbers:
|
|||||||
* It correctly handles `zero`.
|
* It correctly handles `zero`.
|
||||||
* Hyphen does not make a difference: `forty-two` and `forty two` are same.
|
* Hyphen does not make a difference: `forty-two` and `forty two` are same.
|
||||||
So does period or comma.
|
So does period or comma.
|
||||||
* Cases do not make a difference either: `TWO`, `Two`, `two` are same.
|
* Cases do not make a difference either: `TWO`, `Two`, `two` are the same.
|
||||||
* `one` and `a` are interchangeable: `one hundred` and `a hundred` are same.
|
* `one` and `a` are interchangeable: `one hundred` and `a hundred` are the same.
|
||||||
* `and` is optional: `one hundred twenty-three` and `one hundred and twenty-three`
|
* `and` is optional: `one hundred twenty-three` and `one hundred and twenty-three`
|
||||||
are same.
|
are the same.
|
||||||
* It supports every non-negative integer less than 10<sup>15</sup>-1. It uses
|
* It supports every non-negative integer less than 10<sup>15</sup>-1. It uses
|
||||||
the small scale (i.e. American): `billion` is 10<sup>9</sup> and `trillion` is
|
the small scale (i.e. American): `billion` is 10<sup>9</sup> and `trillion` is
|
||||||
10<sup>12</sup>.
|
10<sup>12</sup>.
|
||||||
@@ -121,13 +121,14 @@ It does *not* accept some spelt numbers, which I found mostly irrelevant:
|
|||||||
* A bare `hundred`, `thousand` etc. do not work.
|
* A bare `hundred`, `thousand` etc. do not work.
|
||||||
* `one million million` does not work. Get used to `one trillion`!
|
* `one million million` does not work. Get used to `one trillion`!
|
||||||
|
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
This program is quite portable, only requiring the following:
|
This program is quite portable, only requiring the following:
|
||||||
|
|
||||||
* The signature `int main(int, int)` should be accepted by the linker. (Original
|
* The signature `int main(int, int)` should be accepted by the linker. (Original
|
||||||
version only).
|
version only).
|
||||||
* `char` should be at least 8 bits long (as dictated by the standard), `int`
|
* `char` should be at least 1 byte long (as dictated by the standard), `int`
|
||||||
should be at least 32 bits long, `long long` should be at least 64 bits long.
|
should be at least 32 bits long, `long long` should be at least 64 bits long.
|
||||||
* Both the compiler and execution environment should use an ASCII-compatible
|
* Both the compiler and execution environment should use an ASCII-compatible
|
||||||
character set and two's complement representation.
|
character set and two's complement representation.
|
||||||
@@ -136,16 +137,18 @@ This program is quite portable, only requiring the following:
|
|||||||
|
|
||||||
[trustingtrust]: http://cm.bell-labs.com/who/ken/trust.html
|
[trustingtrust]: http://cm.bell-labs.com/who/ken/trust.html
|
||||||
|
|
||||||
The design of the program explicitly allows for `EOF` which does not equal to -1
|
The design of the program explicitly allows for `EOF` even if it does not equal
|
||||||
(it has to be negative per the standard) and both signed and unsigned `char`,
|
`-1` (it has to be negative per the standard but not necessarily `-1`) and both
|
||||||
for example. Furthermore it is endian-independent.
|
`signed char` and `unsigned char`, for example. Furthermore it is
|
||||||
|
endian-independent.
|
||||||
|
|
||||||
|
|
||||||
### Obfuscations (SPOILERS!)
|
### Obfuscations (SPOILERS!)
|
||||||
|
|
||||||
Many obfuscations used are typical for standard IOCCC entries:
|
Many obfuscations used are typical for standard IOCCC entries:
|
||||||
|
|
||||||
* Two arguments from `main` function are reused as normal variables.
|
* Two arguments from `main()` function are reused as normal variables.
|
||||||
* Every conditional has been replaced with `?:` ternary operator and `||`
|
* Every conditional has been replaced with the `?:` ternary operator and `||`
|
||||||
short-circuiting operator.
|
short-circuiting operator.
|
||||||
* It has exactly three nested `for` loops and nothing else.
|
* It has exactly three nested `for` loops and nothing else.
|
||||||
* Common two's complement tricks: `~-a` instead of `a-1`,
|
* Common two's complement tricks: `~-a` instead of `a-1`,
|
||||||
@@ -161,9 +164,9 @@ Many obfuscations used are typical for standard IOCCC entries:
|
|||||||
Other obfuscations are more subtle:
|
Other obfuscations are more subtle:
|
||||||
|
|
||||||
* The string `"1+DIY/.K430x9G(kC["` is 18 bytes long, but actually 19 bytes
|
* The string `"1+DIY/.K430x9G(kC["` is 18 bytes long, but actually 19 bytes
|
||||||
including the final null character are used.
|
including the final NUL character are used.
|
||||||
* It internally represents numbers as hexadecimal. When the input is `two
|
* It internally represents numbers as hexadecimal. When the input is `two
|
||||||
hundred and three`, it actually writes 0x203 as hexadecimal.
|
hundred and three`, it actually writes `0x203` as hexadecimal.
|
||||||
* Some variables (notably, `n`) have dual uses.
|
* Some variables (notably, `n`) have dual uses.
|
||||||
* The magic number [42][hhgg] makes an appearance.
|
* The magic number [42][hhgg] makes an appearance.
|
||||||
* It has a long long numb-`main`-er within it!
|
* It has a long long numb-`main`-er within it!
|
||||||
@@ -174,24 +177,24 @@ But the most important obfuscation is the clever construction of lookup table.
|
|||||||
The program uses 11 different characters required for recognizing 22 lexemes:
|
The program uses 11 different characters required for recognizing 22 lexemes:
|
||||||
|
|
||||||
```
|
```
|
||||||
zero one tw- th(i)r- fo(u)r- fi- six-
|
zero one tw- th(i)r- fo(u)r- fi- six-
|
||||||
seven- eigh- nin- ten eleven twelve
|
seven- eigh- nin- ten eleven twelve
|
||||||
hundred(s) thousand(s) million(s) billion(s) trillion(s)
|
hundred(s) thousand(s) million(s) billion(s) trillion(s)
|
||||||
a and -teen -ty
|
a and -teen -ty
|
||||||
```
|
```
|
||||||
|
|
||||||
So that they are internally represented as like:
|
So that they are internally represented as like:
|
||||||
|
|
||||||
```
|
```
|
||||||
r n tw- tr- fr- f- s-
|
r n tw- tr- fr- f- s-
|
||||||
sn- g- nn- tn ln twl
|
sn- g- nn- tn ln twl
|
||||||
nr(s) tsan(s) lln(s) blln(s) trlln(s)
|
nr(s) tsan(s) lln(s) blln(s) trlln(s)
|
||||||
a an -tn -ty
|
a an -tn -ty
|
||||||
```
|
```
|
||||||
|
|
||||||
The stemmer recognizes the longest matching prefix, so every lexeme can be
|
The stemmer recognizes the longest matching prefix, so every lexeme can be
|
||||||
recognized by at most three characters (e.g. `trl` instead of `trlln`). This is
|
recognized by at most three characters (e.g. `trl` instead of `trlln`). This is
|
||||||
also handy for ignoring plurals. But that would make that the table does not fit
|
also handy for ignoring plurals. But that would make it so that the table does not fit
|
||||||
in the printable byte---11<sup>2</sup> is already almost 2<sup>7</sup>!
|
in the printable byte---11<sup>2</sup> is already almost 2<sup>7</sup>!
|
||||||
|
|
||||||
The trick is to use octal; three characters (`a`, `b` and `g`) are interpreted
|
The trick is to use octal; three characters (`a`, `b` and `g`) are interpreted
|
||||||
@@ -213,7 +216,7 @@ More spoilers can be found at <https://gist.github.com/lifthrasiir/3909337>
|
|||||||
### Acknowledgement
|
### Acknowledgement
|
||||||
|
|
||||||
The cleaner (size-optimized) version of this program was originally published
|
The cleaner (size-optimized) version of this program was originally published
|
||||||
in my website in July 2011. Sun Park and others have reviewed it and let me
|
in my website in July 2011. Sun Park and others have reviewed it and made me
|
||||||
aware of possible improvements. I'd also like to thank Seo Sanghyeon for
|
aware of possible improvements. I'd also like to thank Seo Sanghyeon for
|
||||||
proof-reading remarks.
|
proof-reading remarks.
|
||||||
|
|
||||||
|
|||||||
+8
-5
@@ -14,17 +14,20 @@ make CC="$CC" everything >/dev/null || exit 1
|
|||||||
# clear screen after compilation so that only the entry is shown
|
# clear screen after compilation so that only the entry is shown
|
||||||
clear
|
clear
|
||||||
|
|
||||||
echo "$ echo Nineteen hundred and eighty-four | ./kang"
|
echo "$ echo Nineteen hundred and eighty-four | ./kang" 1>&2
|
||||||
echo Nineteen hundred and eighty-four | ./kang
|
echo Nineteen hundred and eighty-four | ./kang
|
||||||
|
|
||||||
echo "$ echo uno | ./kang"
|
echo "$ echo uno | ./kang" 1>&2
|
||||||
echo uno | ./kang
|
echo uno | ./kang
|
||||||
|
|
||||||
echo "$ echo trois | ./kang"
|
echo "$ echo trois | ./kang" 1>&2
|
||||||
echo trois | ./kang
|
echo trois | ./kang
|
||||||
|
|
||||||
echo "$ echo fier | ./kang # notice the issue here, see alternate code instead"
|
echo "$ echo fier | ./kang # notice the issue here, see alternate code instead" 1>&2
|
||||||
echo fier | ./kang # notice the issue here, see alternate code instead
|
echo fier | ./kang # notice the issue here, see alternate code instead
|
||||||
|
|
||||||
echo "$ echo \"shest'\" | ./kang"
|
echo "$ echo \"shest'\" | ./kang" 1>&2
|
||||||
echo "shest'" | ./kang
|
echo "shest'" | ./kang
|
||||||
|
|
||||||
|
echo "$ echo dos | ./kang" 1>&2
|
||||||
|
echo dos | ./kang
|
||||||
Reference in new issue
Block a user