This function finds the first non-zero element in a list, and returns its index.
I found this routine in this site. I made some test runs with this function and with my zero searching solution:
The elapsed time was measured with the startTmr() and checkTmr() commands (OS 2.09 in the 92+) and get the result in seconds.
Though the firstnz() function is an elegant solution, the simple While…EndWhile loop in this case is faster a bit, because the number of the zeros in the list isn't too much.
Lucky(1000(items),16(iterations)): While= 106 sec, firstnz= 113 sec.
Lucky(2000,16): While= 258 sec, firstnz= 270 sec.
Of course at Lucky(1000,iter) the items number is approx. 500 because the prg beginning with the odds list.
The number of iterations:
In my previous program the number of iterations was the second parameter. (iter) So, the user must be to guesstimate it. The iter's value is correct when tle last two list's size is equal, or the list's size is less than the step. I tried to check it from the program:
2->m © Loop variable.
string(lck1)->mres[1,1] © Only the final result is in the matrix.
With this program if the number of elements is 1000, the number of needed iterations is 32 (+1) for the final result and the needed time is 178 sec. The row string(lck1)->mres[m,1] was removed from the loop because I got a Memory (Full) error message at approx. 90000 byte free RAM initial value.