Add alt code to 1989/ovdluhe + update README.md
The alt code is based on the author's remarks. It allows one to more easily redefine the macro they refer to (P) in a way that lets them try it out without having to modify the code. Updated .gitignore. Format fixes in README.md.
This commit is contained in:
1 parent
155a1edae2
commit
fcb19507a8
4 files changed
+50
-3
No files matched your search
@@ -1 +1,2 @@
|
|||||||
ovdluhe
|
ovdluhe
|
||||||
|
ovdluhe.alt
|
||||||
@@ -115,8 +115,8 @@ OBJ= ${PROG}.o
|
|||||||
DATA=
|
DATA=
|
||||||
TARGET= ${PROG}
|
TARGET= ${PROG}
|
||||||
#
|
#
|
||||||
ALT_OBJ=
|
ALT_OBJ= ${PROG}.alt.o
|
||||||
ALT_TARGET=
|
ALT_TARGET= ${PROG}.alt
|
||||||
|
|
||||||
|
|
||||||
#################
|
#################
|
||||||
@@ -138,6 +138,9 @@ ${PROG}: ${PROG}.c
|
|||||||
alt: data ${ALT_TARGET}
|
alt: data ${ALT_TARGET}
|
||||||
@${TRUE}
|
@${TRUE}
|
||||||
|
|
||||||
|
${PROG}.alt: ${PROG}.alt.c
|
||||||
|
${CC} ${CFLAGS} $< -o $@ ${LIBS}
|
||||||
|
|
||||||
# data files
|
# data files
|
||||||
#
|
#
|
||||||
data: ${DATA}
|
data: ${DATA}
|
||||||
|
|||||||
+18
-1
@@ -8,7 +8,9 @@
|
|||||||
|
|
||||||
## To build:
|
## To build:
|
||||||
|
|
||||||
|
```sh
|
||||||
make all
|
make all
|
||||||
|
```
|
||||||
|
|
||||||
To get this to compile with a modern CPP, we had to replace `#D` with `#define`.
|
To get this to compile with a modern CPP, we had to replace `#D` with `#define`.
|
||||||
|
|
||||||
@@ -16,19 +18,34 @@ To get this to compile with a modern CPP, we had to replace `#D` with `#define`.
|
|||||||
|
|
||||||
Run the program this way:
|
Run the program this way:
|
||||||
|
|
||||||
|
```sh
|
||||||
./ovdluhe < textfile
|
./ovdluhe < textfile
|
||||||
|
```
|
||||||
|
|
||||||
The program stops when it reaches the end of the template buffer
|
The program stops when it reaches the end of the template buffer
|
||||||
by chance or is killed.
|
by chance or is killed.
|
||||||
|
|
||||||
## Try:
|
## Try:
|
||||||
|
|
||||||
|
```sh
|
||||||
./ovdluhe < ./ovdluhe.c
|
./ovdluhe < ./ovdluhe.c
|
||||||
./ovdluhe < ./ovdluhe.c
|
./ovdluhe < ./ovdluhe.c
|
||||||
|
|
||||||
./ovdluhe < README.md
|
./ovdluhe < README.md
|
||||||
./ovdluhe < README.md
|
./ovdluhe < README.md
|
||||||
|
```
|
||||||
|
|
||||||
|
### Alternate code:
|
||||||
|
|
||||||
|
The author suggested that one varies the definition of `P` from 2 through 10. As
|
||||||
|
it's a `#define` it's easy to set up which [Cody Boone
|
||||||
|
Ferguson](/winners.html#Cody_Boone_Ferguson) did for us. To use try:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make CFLAGS="-DP=9" clobber alt
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `ovdluhe.alt` as you would `ovdluhe`.
|
||||||
|
|
||||||
## Judges' remarks:
|
## Judges' remarks:
|
||||||
|
|
||||||
@@ -38,7 +55,7 @@ recommended. You will get different output each time you run it.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Selected notes from the author:
|
## Author's remarks:
|
||||||
|
|
||||||
This program implements an "Eddington ape" - it generates
|
This program implements an "Eddington ape" - it generates
|
||||||
random text from a supplied template. The template text file
|
random text from a supplied template. The template text file
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
typedef char ape;
|
||||||
|
#define EA register
|
||||||
|
#define EP unsigned
|
||||||
|
#define A 1
|
||||||
|
#define AP (A<<A)
|
||||||
|
#ifndef P
|
||||||
|
#define P (A<<AP)
|
||||||
|
#endif
|
||||||
|
#define AE ((P<<P)<<A)
|
||||||
|
#define PE (((A<<P)<<P)<<P)
|
||||||
|
#define E ((EP)A>>A)
|
||||||
|
#define APE {EA EP ape,ea=AE;while(ea--) e[ea]=E;}
|
||||||
|
PA();
|
||||||
|
;ape a[PE+A],ap,*ae,p[P+A],e[AE];
|
||||||
|
main(){ape pe,*ep=a;srand((EP)time((long)E));
|
||||||
|
while(((*(ep++)=getchar())!=-A)&&((ep-a)<PE));
|
||||||
|
*(ae= --ep)=E;for(ap=E;ap<=P;){APE;if(pe=PA())
|
||||||
|
{putchar(pe);if(ap<P){p[ap]=pe;ap++;}else{
|
||||||
|
ep=p+A;while(*ep) *(ep-A)= *(ep++); *(ep-A)=pe;}}else break;}}
|
||||||
|
PA(){EA ape pe,*ep=a,pa,Ap=E;for(ep=a;ep<ae-P;ep++)
|
||||||
|
if(!strncmp(ep,p,ap)){e[*(ep+ap)]++;Ap++;}if(!Ap)return(Ap);
|
||||||
|
pa=rand()%Ap+A;pe=~E,Ap=!Ap;while((Ap+=e[++pe])<pa);return(pe);}
|
||||||
Reference in new issue
Block a user