Change infinite loop bug status in 1990/theorem
If one passes to the Fibonacci or theorem_bkp program 0 0 it enters an infinite loop repeatedly printing 0. I think this is better to be just documented and not fixed. Another condition where this occurred was fixed but as I recall that might have affected usability and this one in any event does not.
This commit is contained in:
1 parent
d933868b9b
commit
7521206b29
3 files changed
+23
-48
No files matched your search
@@ -1,3 +1,4 @@
|
||||
theorem
|
||||
fibonacci
|
||||
fibonacci.c
|
||||
mariano
|
||||
|
||||
+17
-8
@@ -29,7 +29,7 @@ about `gets()` at linking or runtime. Thank you Cody for your assistance!
|
||||
|
||||
[Yusuke Endoh](/winners.html#Yusuke_Endoh) pointed out that `atof` nowadays
|
||||
needs `#include <stdlib.h>` which was used in order to get this to work
|
||||
initially. Thank you Yusuke!
|
||||
initially (prior to this the output was incomplete). Thank you Yusuke!
|
||||
|
||||
|
||||
## To run:
|
||||
@@ -54,20 +54,29 @@ y1 - initial value (y(x1) == y1)
|
||||
./theorem y 0 1 0.1 1
|
||||
```
|
||||
|
||||
### Known bug with `fibonacci.c` and `theorem_bkp.c`:
|
||||
### INABIAF - it's not a bug it's a feature! :-)
|
||||
|
||||
If the two args added up equals 0 the program will enter an infinite loop,
|
||||
printing 0 over and over again. Cody fixed another condition where this happens
|
||||
but this has not been fixed. See [bugs.md](/bugs.md) for more details.
|
||||
If the two args passed to `fibonacci` and `theorem_bkp` equals 0 it will
|
||||
print 0 over and over again in an infinite loop. In this case it should not be
|
||||
fixed (another condition where this occurred was fixed as it affected usability
|
||||
of the program).
|
||||
|
||||
BTW: why can't the fix:
|
||||
|
||||
```c
|
||||
if (a[1]==NULL||a[2]==NULL||a[3]==NULL||a[4]==NULL||a[5]==NULL) return 1;
|
||||
```
|
||||
|
||||
be changed to just test the value of `A` when `a` is argv and `A` is argc?
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
The program's source implements four functions, all from the
|
||||
same source file!
|
||||
|
||||
When you compile theorem.c as is and run with 5 args, it numerically
|
||||
solves the equation `y'=f(x,y)`, with a step size of `h`, over the interval
|
||||
`x=[x1,x2]`, with the initial condition of `y(x1)=y1`.
|
||||
When you compile theorem.c as is and run with 5 args, it numerically solves the
|
||||
equation `y'=f(x,y)`, with a step size of `h` (see above usage), over the
|
||||
interval `x=[x1,x2]`, with the initial condition of `y(x1)=y1`.
|
||||
|
||||
The 'expression' `f(x,y)` is any function of `x` and `y` with the
|
||||
operators:
|
||||
|
||||
@@ -596,48 +596,13 @@ so it should stay with this note.
|
||||
|
||||
|
||||
## [1990/theorem](1990/theorem/theorem.c) ([README.md](1990/theorem/README.md))
|
||||
## STATUS: known bug - please help us fix
|
||||
## STATUS: INABIAF - please **DO NOT** fix
|
||||
|
||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed many bugs that
|
||||
prevented this from working properly (including segfaults) but one bug known to
|
||||
exist remains: if `theorem_bkp` or `fibonacci` is passed two zeros the program
|
||||
will enter an infinite loop, printing 0 over and over again (another condition
|
||||
where this occurred was fixed).
|
||||
|
||||
Cody provides some hints here:
|
||||
|
||||
0. The function in `theorem.c` that matters is `w` (see below for definition).
|
||||
1. However adding checks for the value being > 0 does not work due to the way the
|
||||
code is generated. See below.
|
||||
|
||||
`w()` looks like this:
|
||||
|
||||
```c
|
||||
w(g,R,u)float*g,u;char R;
|
||||
/**/{int b,f;if(A>2){A=atoi(a[1]);b=atoi(a[2]);while((f=A+b)<15000){printf("%d\n",f);A=b;b=f;}}}
|
||||
```
|
||||
|
||||
But as far as point 1 above changing it to be:
|
||||
|
||||
```c
|
||||
/**/{int b,f;if(A>2){A=atoi(a[1]);b=atoi(a[2]);while(f!=0&&(f=A+b)<15000){printf("%d\n",f);A=b;b=f;}}}
|
||||
```
|
||||
|
||||
and similar (like checking `>0`, doing a `do..while`, doing an `if` before the
|
||||
while etc.) cause compilation errors.
|
||||
|
||||
Can you fix this? We welcome your help!
|
||||
|
||||
BTW: one of the important fixes for `fibonacci` to work is:
|
||||
|
||||
```diff
|
||||
-/**/{int b,f;A=atoi(++a);b=atoi(++a);while((f=A+b)<15000){printf("%d\n",f);A=b;b=f;}}
|
||||
+/**/{int b,f;if(A>2){A=atoi(a[1]);b=atoi(a[2]);while((f=A+b)<15000){printf("%d\n",f);A=b;b=f;}}}
|
||||
```
|
||||
|
||||
Observe the check for the number of args and the calls to `atoi()` have been
|
||||
changed a bit too.
|
||||
|
||||
prevented this from working properly (including segfaults) but one thing to note
|
||||
is that if you pass two zeroes to `theorem_bkp` or `fibonacci` the program
|
||||
will enter an infinite loop, printing 0 over and over again; another condition
|
||||
where this occurred was fixed but this one should not be fixed. Thank you.
|
||||
|
||||
## [1990/westley](1990/westley/westley.c) ([README.md](1990/westley/README.md))
|
||||
## STATUS: INABIAF - please **DO NOT** fix
|
||||
|
||||
Reference in new issue
Block a user