Average value in variable array?
lardom
Posts: 1,659
What is the syntax in Spin for calculating the average value in a variable array? (If you can only add one element at a time a block of code could get really large).

Comments
pub average(p_array, elements) | acc acc := 0 ' clear accumulator repeat elements ' total all acc += long[p_array] ' get one p_array += 4 ' point to next element return acc / elements ' return averageIf memory serves me, Phil (PhiPi) had some code to do a running average posted a while back -- you might want to do a search for that.
@Mike Green, Thanks.
VAR long AveDistance[6], PingDistance[9], Wide_Path, Rotate_Amount PUB Find_Corridor | i, j i:= 0 repeat j from 1 to 6 repeat 4 AveDistance[j]+= PingDistance[i] i++ AveDistance[j]/= 4 i-= 2 repeat j from 1 to 6 if AveDistance[j] > Wide_Path Wide_Path := AveDistance[j] Rotate_Amount := j