Merge pull request #1111 from xexyl/1989-ovdluhe-loop-fix

This commit is contained in:
Landon Curt Noll authored and GitHub committed 2023-10-19 11:26:46 -07:00
commit b3b00b2455
5 files changed
+15 -7

No files matched your search

+1 -1
View File
@@ -68,7 +68,7 @@ CINCLUDE=
# Optimization # Optimization
# #
OPT= -O3 OPT=
# Default flags for ANSI C compilation # Default flags for ANSI C compilation
# #
+2 -2
View File
@@ -38,8 +38,7 @@ by chance or is killed.
### Alternate code: ### Alternate code:
The author suggested that one varies the definition of `P` from 2 through 10. As 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 it's a `#define` it's easy to set up. To use try:
Ferguson](/winners.html#Cody_Boone_Ferguson) did for us. To use try:
```sh ```sh
make CFLAGS="-DP=9" clobber alt make CFLAGS="-DP=9" clobber alt
@@ -47,6 +46,7 @@ make CFLAGS="-DP=9" clobber alt
Use `ovdluhe.alt` as you would `ovdluhe`. Use `ovdluhe.alt` as you would `ovdluhe`.
## Judges' remarks: ## Judges' remarks:
Run this program using your favorite text file as input. Files Run this program using your favorite text file as input. Files
+1 -1
View File
@@ -20,7 +20,7 @@ main(){ape pe,*ep=a;srand((EP)time((long)E));
while(((*(ep++)=getchar())!=-A)&&((ep-a)<PE)); while(((*(ep++)=getchar())!=-A)&&((ep-a)<PE));
*(ae= --ep)=E;for(ap=E;ap<=P;){APE;if(pe=PA()) *(ae= --ep)=E;for(ap=E;ap<=P;){APE;if(pe=PA())
{putchar(pe);if(ap<P){p[ap]=pe;ap++;}else{ {putchar(pe);if(ap<P){p[ap]=pe;ap++;}else{
ep=p+A;while(*ep) *(ep-A)= *(ep++); *(ep-A)=pe;}}else break;}} 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++) 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); 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);} pa=rand()%Ap+A;pe=~E,Ap=!Ap;while((Ap+=e[++pe])<pa);return(pe);}
+1 -1
View File
@@ -14,7 +14,7 @@ main(){ape pe,*ep=a;srand((EP)time((long)E));
while(((*(ep++)=getchar())!=-A)&&((ep-a)<PE)); while(((*(ep++)=getchar())!=-A)&&((ep-a)<PE));
*(ae= --ep)=E;for(ap=E;ap<=P;){APE;if(pe=PA()) *(ae= --ep)=E;for(ap=E;ap<=P;){APE;if(pe=PA())
{putchar(pe);if(ap<P){p[ap]=pe;ap++;}else{ {putchar(pe);if(ap<P){p[ap]=pe;ap++;}else{
ep=p+A;while(*ep) *(ep-A)= *(ep++); *(ep-A)=pe;}}else break;}} 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++) 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); 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);} pa=rand()%Ap+A;pe=~E,Ap=!Ap;while((Ap+=e[++pe])<pa);return(pe);}
+10 -2
View File
@@ -494,8 +494,16 @@ you know how?
## [1989/ovdluhe](1989/ovdluhe/ovdluhe.c) ([README.md](1989/ovdluhe/README.md])) ## [1989/ovdluhe](1989/ovdluhe/ovdluhe.c) ([README.md](1989/ovdluhe/README.md]))
Cody provided an [alternate version](1989/ovdluhe/ovdluhe.alt.c) based on the Cody fixed an infinite loop where the program would print the same thing over
author's remarks. See the README.md for details. and over again, flooding the screen. The problem is that there was a `for` loop
that by necessity had to not have an increment stage but only in the `if` path
(in the loop itself) did the pointer get updated. Looking at the code it might
be that it can work just as well by adding the increment in the loop itself but
this was not done.
Cody also provided an [alternate version](1989/ovdluhe/ovdluhe.alt.c) based on the
author's remarks. See the README.md for details. The fix described above was
fixed in this version too, after it was discovered and fixed.
## [1989/paul](1989/paul/paul.c) ([README.md](1989/paul/README.md])) ## [1989/paul](1989/paul/paul.c) ([README.md](1989/paul/README.md]))