Merge pull request #204 from xexyl/1992-gson
Make 1992/gson not use gets() + update README.md
This commit is contained in:
4 files changed
+37
-26
No files matched your search
@@ -1,2 +1,2 @@
|
|||||||
gson
|
gson
|
||||||
og
|
ag
|
||||||
+2
-2
@@ -114,7 +114,7 @@ PROG= ${ENTRY}
|
|||||||
#
|
#
|
||||||
OBJ= ${PROG}.o
|
OBJ= ${PROG}.o
|
||||||
DATA=
|
DATA=
|
||||||
TARGET= ${PROG} og
|
TARGET= ${PROG} ag
|
||||||
#
|
#
|
||||||
ALT_OBJ=
|
ALT_OBJ=
|
||||||
ALT_TARGET=
|
ALT_TARGET=
|
||||||
@@ -134,7 +134,7 @@ all: data ${TARGET}
|
|||||||
${PROG}: ${PROG}.c
|
${PROG}: ${PROG}.c
|
||||||
${CC} ${CFLAGS} $< -o $@ ${LIBS}
|
${CC} ${CFLAGS} $< -o $@ ${LIBS}
|
||||||
|
|
||||||
og: ${PROG}
|
ag: ${PROG}
|
||||||
${RM} -f $@
|
${RM} -f $@
|
||||||
${LN} $< $@
|
${LN} $< $@
|
||||||
|
|
||||||
|
|||||||
+32
-21
@@ -10,11 +10,23 @@
|
|||||||
|
|
||||||
make all
|
make all
|
||||||
|
|
||||||
### To run
|
### To run:
|
||||||
|
|
||||||
./og word word2 word3 < /path/to/dictionary
|
./ag word word2 word3 < /path/to/dictionary
|
||||||
|
|
||||||
## Judges' comment
|
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this entry to not
|
||||||
|
use gets(). Previously it had a buffer size of 256 which could easily overflow.
|
||||||
|
Now in this entry `gets()` is used in a more complicated way (first `m` is set
|
||||||
|
to `*++p` in a for loop where `p` is argv and then later `m` is set to point to
|
||||||
|
`h` which is of size 256) and trying to change it to use fgets() proved more a
|
||||||
|
problem. Since the input must come from the command line Cody changed the buffer
|
||||||
|
size to `ARG_MAX+1` which should be enough especially since the command expects
|
||||||
|
redirecting a dictionary file as part of the command line. This also makes it
|
||||||
|
possible for longer strings to be read (in case the `gets()` was not used in a
|
||||||
|
loop). Thank you Cody for your assistance!
|
||||||
|
|
||||||
|
|
||||||
|
## Judges' comment:
|
||||||
|
|
||||||
Determine where your system dictionary is located. You may find
|
Determine where your system dictionary is located. You may find
|
||||||
it located in one of the following places:
|
it located in one of the following places:
|
||||||
@@ -38,7 +50,7 @@
|
|||||||
names listed above. Run this program to find the anagrams they
|
names listed above. Run this program to find the anagrams they
|
||||||
weren't allowed to print!
|
weren't allowed to print!
|
||||||
|
|
||||||
## Author's comments
|
## Author's comments:
|
||||||
|
|
||||||
The name of the game:
|
The name of the game:
|
||||||
|
|
||||||
@@ -47,14 +59,14 @@
|
|||||||
coincidence it happens to be the author's initials.
|
coincidence it happens to be the author's initials.
|
||||||
|
|
||||||
|
|
||||||
What it does:
|
### What it does:
|
||||||
|
|
||||||
AG takes one or more words as arguments, and tries to find
|
AG takes one or more words as arguments, and tries to find
|
||||||
anagrams of those words, i.e. words or sentences containing
|
anagrams of those words, i.e. words or sentences containing
|
||||||
exactly the same letters.
|
exactly the same letters.
|
||||||
|
|
||||||
|
|
||||||
How to use it:
|
### How to use it:
|
||||||
|
|
||||||
To run AG, you need a dictionary file consisting of distinct words
|
To run AG, you need a dictionary file consisting of distinct words
|
||||||
in the natural language of your choice, one word on each line. If
|
in the natural language of your choice, one word on each line. If
|
||||||
@@ -75,24 +87,22 @@
|
|||||||
meaningful than those consisting of dozens of very short words, the
|
meaningful than those consisting of dozens of very short words, the
|
||||||
number of words in the anagrams is limited to 3 by default. This
|
number of words in the anagrams is limited to 3 by default. This
|
||||||
limit can be changed using a numeric command line option, as in
|
limit can be changed using a numeric command line option, as in
|
||||||
"ag -4 international obfuscated c code contest </usr/dict/words".
|
`./ag -4 international obfuscated c code contest </usr/dict/words`.
|
||||||
|
|
||||||
Bugs:
|
### Bugs:
|
||||||
|
|
||||||
- There is no error checking
|
- There is no error checking.
|
||||||
- Standard input must be seekable, so you can't pipe the dictionary
|
- Standard input must be seekable, so you can't pipe the dictionary into AG.
|
||||||
into AG.
|
- The input sentence and each line in the dictionary may contain at most 32
|
||||||
- The input sentence and each line in the dictionary may contain
|
distinct letters, and each letter may occur at most 15 times.
|
||||||
at most 32 distinct letters, and each letter may occur at most 15
|
- Words in the dictionary may be at most 255 bytes long.
|
||||||
times.
|
- AG cannot handle characters that sign-extend to negative values.
|
||||||
- Words in the dictionary may be at most 255 bytes long
|
- Although AG works on both 16-bit and 32-bit machines, the size of the problems
|
||||||
- AG cannot handle characters that sign-extend to negative values
|
it can solve is severely limited on machines that limit the stack size to 64k or
|
||||||
- Although AG works on both 16-bit and 32-bit machines,
|
less.
|
||||||
the size of the problems it can solve is severely limited
|
|
||||||
on machines that limit the stack size to 64k or less.
|
|
||||||
|
|
||||||
|
|
||||||
Obfuscatory notes:
|
### Obfuscatory notes:
|
||||||
|
|
||||||
As you can see, AG takes advantage of the new '92 whitespace rules to
|
As you can see, AG takes advantage of the new '92 whitespace rules to
|
||||||
achieve a clear, readable, self-documenting layout. The identifiers
|
achieve a clear, readable, self-documenting layout. The identifiers
|
||||||
@@ -104,7 +114,8 @@
|
|||||||
careful choice of algorithms. Some of the finer points of those
|
careful choice of algorithms. Some of the finer points of those
|
||||||
algorithms are outlined in the rot-13 encoded spoiler below.
|
algorithms are outlined in the rot-13 encoded spoiler below.
|
||||||
|
|
||||||
How it works: (ROT13 to read)
|
### How it works: (ROT13 to read)
|
||||||
|
|
||||||
|
|
||||||
Urer sbyybjf n qrfpevcgvba bs fbzr bs gur qngn fgehpgherf naq
|
Urer sbyybjf n qrfpevcgvba bs fbzr bs gur qngn fgehpgherf naq
|
||||||
nytbevguzf hfrq ol NT. Vg vf ol ab zrnaf pbzcyrgr, ohg vg znl uryc
|
nytbevguzf hfrq ol NT. Vg vf ol ab zrnaf pbzcyrgr, ohg vg znl uryc
|
||||||
|
|||||||
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <limits.h>
|
||||||
long a
|
long a
|
||||||
[4],b[
|
[4],b[
|
||||||
4],c[4]
|
4],c[4]
|
||||||
,d[0400],e=1;
|
,d[0400],e=1;
|
||||||
typedef struct f{long g
|
typedef struct f{long g
|
||||||
,h,i[4] ,j;struct f*k;}f;f g,*
|
,h,i[4] ,j;struct f*k;}f;f g,*
|
||||||
l[4096 ]; char h[256],*m,k=3;
|
l[4096 ]; char h[ARG_MAX+1],*m,k=3;
|
||||||
long n (o, p,q)long*o,*p,*q;{
|
long n (o, p,q)long*o,*p,*q;{
|
||||||
long r =4,s,i=0;for(;r--;s=i^
|
long r =4,s,i=0;for(;r--;s=i^
|
||||||
*o^*p, i=i&*p|(i|*p)&~*o++,*q
|
*o^*p, i=i&*p|(i|*p)&~*o++,*q
|
||||||
|
|||||||
Reference in new issue
Block a user