From c19a19923fd17279c1c0de7641338e0cbe111726 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 16 Oct 2023 05:29:28 -0700 Subject: [PATCH] Improve my fixes to 2000/natori When Landon initially tried getting it to work he ended up making the include files in the Makefile (-include ...) to restore it to be a one-liner but this was actually an error as it was not a one-liner but rather a best small program; the original code has the #includes in the source file. At the same time I made the code itself one-line as it was indeed one line (the source of the problem, of course). Now the fixed code (segfaulted with gcc, failed to compile with clang), both original and alt version (southern hemisphere: based on the author's remarks but with my fixes applied) that I added, looks more like the original. --- 2000/natori/Makefile | 2 +- 2000/natori/README.md | 8 ++++---- 2000/natori/natori.alt.c | 7 +++---- 2000/natori/natori.c | 7 +++---- thanks-for-fixes.md | 6 ++++++ 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/2000/natori/Makefile b/2000/natori/Makefile index b6dced880..b69fda891 100644 --- a/2000/natori/Makefile +++ b/2000/natori/Makefile @@ -62,7 +62,7 @@ CDEFINE= -Wno-error -Wno-implicit-function-declaration -Wno-implicit-int \ # Include files that are needed to compile # -CINCLUDE= -include stdlib.h -include math.h +CINCLUDE= # Optimization # diff --git a/2000/natori/README.md b/2000/natori/README.md index 863536b40..3f926a685 100644 --- a/2000/natori/README.md +++ b/2000/natori/README.md @@ -23,9 +23,8 @@ Alternate code section below for more details. ## Try: -```sh -echo "Do or do not. There is no try." -``` +Try modifying the code so that it will show another Moon phase based on input +or else just by the code itself. Bonus points if you can make it show all! ### Alternate code: @@ -45,7 +44,8 @@ What happens if you run it in the northern hemisphere? Are there any differences? Can you identify any Moon phases that result in the same output of both -versions? +versions? Or are there any? + ## Judges' remarks: diff --git a/2000/natori/natori.alt.c b/2000/natori/natori.alt.c index ce74329cd..3b11bd21f 100644 --- a/2000/natori/natori.alt.c +++ b/2000/natori/natori.alt.c @@ -1,4 +1,3 @@ -double l; -int moon(int _, int o, int O){ -return putchar((_--+22&&_+44&&main(_,-43,_),_&&(int)o)?(main(-43,(int)++o,(int)O),((l=((int)o+21)/sqrt(3-(int)O*22-(int)O*(int)O),l*l<4&&(fabs(((time(0)-607728)%2551443)/405859.-4.7+acos(-l/2))<1.57))[" #"])):10);} -main(int _,char**o,char**O){return moon(_, (int)o, (int)O); } +#include +#include +double l; int moon(int _, int o, int O){ return putchar((_--+22&&_+44&&main(_,-43,_),_&&(int)o)?(main(-43,(int)++o,(int)O),((l=((int)o+21)/sqrt(3-(int)O*22-(int)O*(int)O),l*l<4&&(fabs(((time(0)-607728)%2551443)/405859.-4.7+acos(-l/2))<1.57))[" #"])):10);} main(int _,char**o,char**O){return moon(_, (int)o, (int)O); } diff --git a/2000/natori/natori.c b/2000/natori/natori.c index 8f0c7ac16..227aafb85 100644 --- a/2000/natori/natori.c +++ b/2000/natori/natori.c @@ -1,4 +1,3 @@ -double l; -int moon(int _, int o, int O){ -return putchar((_--+22&&_+44&&main(_,-43,_),_&&(int)o)?(main(-43,(int)++o,(int)O),((l=((int)o+21)/sqrt(3-(int)O*22-(int)O*(int)O),l*l<4&&(fabs(((time(0)-607728)%2551443)/405859.-4.7+acos(l/2))<1.57))[" #"])):10);} -main(int _,char**o,char**O){return moon(_, (int)o, (int)O); } +#include +#include +double l;int moon(int _, int o, int O){return putchar((_--+22&&_+44&&main(_,-43,_),_&&(int)o)?(main(-43,(int)++o,(int)O),((l=((int)o+21)/sqrt(3-(int)O*22-(int)O*(int)O),l*l<4&&(fabs(((time(0)-607728)%2551443)/405859.-4.7+acos(l/2))<1.57))[" #"])):10);}main(int _,char**o,char**O){return moon(_, (int)o, (int)O); } diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index bf46a67f7..c32199d36 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -1030,6 +1030,12 @@ segfault when run or not compile at all (gcc and clang respectively). Cody also provided alternate code that supports the southern hemisphere. +Later on Cody restored the `#include`s in the source code which had been changed +by us to make it a one-liner again but this was an error as it was not a +one-liner but rather a small program. At the same point Cody made the code +itself a one-line like the code is in the original entry. Now it looks much more +like the original entry but with the two fixes. + ## [2000/thadgavin](2000/thadgavin/thadgavin.c) ([README.md](2000/thadgavin/README.md]))