|
![](/i/fill.gif) |
In article <2vk### [at] micha riser> , Micha Riser <mri### [at] gmx net>
wrote:
> Can you do it without extra variable?
I can do it with i and n
> One solution working in pov is:
>
> #declare goon=1;
> #declare i=0;
> #while ((i<n)&(goon=1))
> #if (a[i]=0)
> #declare i=i+1;
> #else
> #declare goon=0;
> #end
> #end
>
> So this can impossible be better style. Please enlighten me with your
> solution.
Of course it depends on what exactly you want to do with the result to find
an optimal solution (in particular one that doesn't process the whole
array). This macro should do what you want and it does not need more
variables:
#macro findzero(a, n)
#local i = n;
#while(i >= 0)
#if(a[i] != 0)
#declare n = i;
#end
#declare i = i - 1;
#end
#end
#declare myarray = array[5]
#declare myarray[0] = 0;
#declare myarray[1] = 0;
#declare myarray[2] = 0;
#declare myarray[3] = 0;
#declare myarray[4] = 0;
#declare p = 4;
findzero(myarray, p)
#debug str(p,1,1)
#declare myarray[3] = 4;
#declare myarray[4] = 2;
#declare p = 4;
findzero(myarray, p)
#debug str(p,1,1)
#declare myarray[0] = 6;
#declare myarray[1] = 7;
#declare myarray[2] = 3;
#declare p = 4;
findzero(myarray, p)
#debug str(p,1,1)
#declare myarray[2] = 0;
#declare p = 4;
findzero(myarray, p)
#debug str(p,1,1)
Post a reply to this message
|
![](/i/fill.gif) |