Files
Cody Boone Ferguson f882ea84dd Fix infinite loop in 1989/ovdluhe
As Landon said it is a bug (after I asked about it) I have fixed it.
Without this fix the program printed the same thing over and over again
in some cases. The problem was a for() loop that didn't always have the
pointer incremented. It looks like I could have got away with just
updating the increment part of the loop but I didn't do that as I didn't
see it at first.

The optimiser was disabled. That might not be strictly necessary but I
had it disabled for a time so I have kept it disabled.

Also I removed my name in the README.md: this was missed when the much
better idea of a general thanks file was come up with. When testing the
fix I came across part of my name which made me check. I have not yet
typo/format checked this file or any of 1989 so that was not done. That
might or might not happen in part or in whole later today but either way
it'll be started soon.
2023-10-19 05:19:58 -07:00

21 lines
711 B
C

#include <string.h>
typedef char ape
#define EA register
#define EP unsigned
#define A 1
#define AP (A<<A)
#define P (A<<AP)
#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;}
;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;++ap;}}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);}