Equilibrium index: Difference between revisions

no edit summary
No edit summary
Line 2,142:
 
We could have used <tt>.pairs</tt> instead of <tt>.keys</tt> to save the cost of <tt>@list</tt> lookups, but that would change each <tt>%h</tt> value to an Array of Pairs, which would complicate the return line.
=={{header|Red}}==
 
<lang Rebol>Red []
eqindex: func [a [block!]] [
collect [
repeat ind length? a [ if (sum skip a ind) = sum copy/part a ind - 1 [ keep ind ] ]
]
]
prin "(1 based) equ indices are: "
probe eqindex [-7 1 5 2 -4 3 0]
</lang>
{{out}}
<pre>(1 based) equ indices are: [4 7]</pre>
=={{header|REXX}}==
===version 1===