To correct the bug, is it this?
if outputarray[i] < 0 && outputarray[i+1] >= 0
count += 1
end
Factoring in that Julia begins indexing from 1.
On Wednesday, July 30, 2014 4:41:43 PM UTC-4, John Myles White wrote:
>
> This pseudocode almost works. Just replace Int64[1:len(outputarray)] with
> 1:length(outputarray).
>
> There’s also a bug in your core logic, but I’ll leave fixing that as an
> exercise to the reader.
>
> — John
>
> On Jul 30, 2014, at 1:03 PM, [email protected] <javascript:> wrote:
>
> Hi guys,
>
> I asked this in a previous thread, but because that diverged off-topic
> from my existing question, I decided to create a new thread.
>
> Anyhow, say I have an array
>
> outputarray =
> Float64[-1.23423,-3.23423,-2.34234,-2.12342,1.23234,2.23423,-2.23432,5.2341,0.01111,1.23423]
>
> This array lists the output of some function. I want to count the number
> of times that the function passes by or equals 0 while emerging from a
> negative f(x).
>
> In pseudocode, I want to do:
>
> function counter(outputarray)
> count = 0
> for i in Int64[1:len(outputarray)]
> if outputarray[i] >= 0 && outputarray[i-1] < 0
> count += 1
> end
> end
> return count
> end
>
> What would be the most efficient way of doing this in Julia?
>
> Thanks,
> Wally
>
>
>