diff --git a/1993/schnitzi/README.md b/1993/schnitzi/README.md index 63ba72009..0f0f920f2 100644 --- a/1993/schnitzi/README.md +++ b/1993/schnitzi/README.md @@ -9,22 +9,44 @@ make all -[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made this use `fgets()` -not `gets()` to make it safer. Thank you Cody for your assistance! +[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to not +segfault when no file is specified or the file cannot be opened for reading. he +also made this use `fgets()` not `gets()` to make it safer. Thank you Cody for +your assistance! -### To run +### To run: - ./schnitzi file + ./schnitzi file - where: +where: + file a file containing some text -## Judges' comments +## Try: - After this program prints the contents of 'file', ask it - some questions related to the text. + ./schnitzi schnitzi.info + # ask some questions suggested by the author, noted below + +We also suggest you ask the program: + + Who is Mark Schnitzus? + +Notice how it still manages to answer the question despite there being an +intentional spelling error there. + +Try feeding the program source to the program and ask both: + + What is cat ? + What is cat? + + +## Judges' comments: + +After this program prints the contents of 'file', ask it +some questions related to the text. - The author suggests the following questions when using schnitzi.info: +The author suggests the following questions when using schnitzi.info: + Who is Mark Schnitzius? What exactly does this program do? @@ -35,65 +57,57 @@ not `gets()` to make it safer. Thank you Cody for your assistance! Is it true that Elvis is alive? Do colorless green ideas sleep furiously? - We suggest you try using the body (minus the header and signature line) - of a Usenet article. You might want to try something from alt.flame. :-) +We suggest you try using the body (minus the header and signature line) +of a Usenet article. You might want to try something from alt.flame. :-) - If you have a ' in the question this entry may fail. +NOTE: If you have a ' in the question this entry may fail. - NOTE: This entry uses `gets()` so you might get a warning when compiling and - running this entry. +NOTE: The author may also be contacted at: marks@aldrin.ksc.nasa.gov. - NOTE: this entry will likely segfault if you do not provide it with a data - file. +## Author's comments: - NOTE: The author may also be contacted at: marks@aldrin.ksc.nasa.gov +I wanted to write a program that would read in a text file in +natural language (such as English) and answer questions about that +text file. I thought this might be a complicated task, and I was +right -- it took me over 800 bytes. Of course, it doesn't always +work, but that's AI for you. -## Author's comments +This program accepts the name of a text file as the first +parameter. For example, to run it on the supplied data file called +'info' you would type `./schnitzi info`. It echoes the file, then +gives you a prompt where you may type in questions about that text. +The more words you use which are actually present in the text file, +the better results you get. You'll need to hit `ctrl-c` to break out +of the program. Just hitting `return` at the prompt will reprint the +paragraph. - I wanted to write a program that would read in a text file in - natural language (such as English) and answer questions about that - text file. I thought this might be a complicated task, and I was - right -- it took me over 800 bytes. Of course, it doesn't always - work, but that's AI for you. +If you're curious as to how it works, I guess you could feed in the +source as the input file and ask "How does this work?" at the prompt, +but I'm not guaranteeing any results... - This program accepts the name of a text file as the first - parameter. For example, to run it on the supplied data file called - 'info' you would type 'schnitzi info'. It echoes the file, then - gives you a prompt where you may type in questions about that text. - The more words you use which are actually present in the text file, - the better results you get. You'll need to hit to break out - of the program. Just hitting at the prompt will reprint the - paragraph. +### Compilation notes: - If you're curious as to how it works, I guess you could feed in the - source as the input file and ask "How does this work?" at the prompt, - but I'm not guaranteeing any results... +- The use of 'strcasecmp' may be non-standard. 'strcmp' can be substituted for +it, with a slight performance penalty. - Compilation notes: +- This program depends on the first command-line parameter, typically called +argv[0], to hold the name of the executable. It is my understanding that this +property of argv[0] is not guaranteed on some systems. - o The use of 'strcasecmp' may be non-standard. 'strcmp' - can be substituted for it, with a slight performance penalty. +### Obfuscation: - o This program depends on the first command-line parameter, typically - called argv[0], to hold the name of the executable. It is my under- - standing that this property of argv[0] is not guaranteed on some - systems. +- It uses a hidden string to test for punctuation. - This program is obfuscated in the following ways: +- The layout, variable names, and expression format have been chosen in such a +way as to cause visual confusion. - o It uses a hidden string to test for punctuation; +- It uses uses external 'system' calls to echo the text file and break up the +question into individual words with a recursive call. - o The layout, variable names, and expression format - have been chosen in such a way as to cause visual confusion; +- It uses a clever hack to simulate artificial intelligence. - o It uses uses external 'system' calls to echo the text - file and break up the question into individual words with a - recursive call; - - o It uses a clever hack to simulate artificial intelligence. - - The text for the info file, by the way, consists largely of headlines - from the Weekly World News. +The text for the info file, by the way, consists largely of headlines +from the Weekly World News. ## Copyright and CC BY-SA 4.0 License: diff --git a/1993/schnitzi/schnitzi.c b/1993/schnitzi/schnitzi.c index 55c4232b3..a51e8ab4c 100644 --- a/1993/schnitzi/schnitzi.c +++ b/1993/schnitzi/schnitzi.c @@ -13,9 +13,9 @@ ( lll>l1 ) li|=! ( l[3*l1+++3 ] -ll[strlen ( ll)-1] ) ;return ( li ) ;}main ( ll,lll - ) char*lll[];{char l1 [ 111][21],li1[111][21 ] ,il1[111],i1l + ) char*lll[];{if(ll<2)return 1;char l1 [111][21], li1[111][21],il1[111],i1l [ 111 ] ;int lli,l11,l1l,li/* ( */,ll1,il,l;FILE*f;if(ll-2 - ) {f=fopen ( lll[1],"r" ) ;lli=l=ll1=il=!1;while + ) {f=fopen ( lll[1],"r" );if(!f)return 1;lli=l=ll1=il=!1;while ( fscanf(f,"%s",l1[lli] ) +1){li=ii ( l1[lli],3 ) ;iii ( l1[lli] ) ;l1l=l11=!1;while ( l1l>-ll ) {iii ( lll[-l1l]