Equilibrium index: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: shave off one line)
(→‎{{header|AppleScript}}: Added straightforward solution.)
Line 389: Line 389:


=={{header|AppleScript}}==
=={{header|AppleScript}}==
===Functional===
{{Trans|JavaScript}}(ES6 version)
{{Trans|JavaScript}}(ES6 version)
<syntaxhighlight lang="applescript">-- equilibriumIndices :: [Int] -> [Int]
<syntaxhighlight lang="applescript">-- equilibriumIndices :: [Int] -> [Int]
Line 570: Line 571:
{{Out}}
{{Out}}
<pre>{{3, 6}, {}, {1}, {0, 1, 2, 3, 4, 5, 6}, {0}, {}}</pre>
<pre>{{3, 6}, {}, {1}, {0, 1, 2, 3, 4, 5, 6}, {0}, {}}</pre>
----
===Straightforward===
<syntaxhighlight lang="applescript">on equilibriumIndices(sequence)
script o
property seq : sequence
property output : {}
end script
set loSum to 0
set hiSum to 0
repeat with value in o's seq
set hiSum to hiSum + value
end repeat
repeat with i from 1 to (count o's seq)
set value to o's seq's item i
set hiSum to hiSum - value
if (hiSum = loSum) then set o's output's end to i
set loSum to loSum + value
end repeat
return o's output
end equilibriumIndices

equilibriumIndices({-7, 1, 5, 2, -4, 3, 0})</syntaxhighlight>

{{output}}
AppleScript uses 1-based indices.
<syntaxhighlight lang="applescript">{4, 7}</syntaxhighlight>


=={{header|Arturo}}==
=={{header|Arturo}}==