How to resolve the algorithm Equilibrium index step by step in the Yorick programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Equilibrium index step by step in the Yorick programming language

Table of Contents

Problem Statement

An equilibrium index of a sequence is an index into the sequence such that the sum of elements at lower indices is equal to the sum of elements at higher indices.

For example, in a sequence

A

{\displaystyle A}

: 3   is an equilibrium index, because: 6   is also an equilibrium index, because: (sum of zero elements is zero) 7   is not an equilibrium index, because it is not a valid index of sequence

A

{\displaystyle A}

.

Write a function that, given a sequence, returns its equilibrium indices (if any). Assume that the sequence may be very long.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Equilibrium index step by step in the Yorick programming language

Source code in the yorick programming language

func equilibrium_indices(A) {
    return where(A(psum) == A(::-1)(psum)(::-1));
}

  

You may also check:How to resolve the algorithm Symmetric difference step by step in the TUSCRIPT programming language
You may also check:How to resolve the algorithm Truth table step by step in the Tcl programming language
You may also check:How to resolve the algorithm McNuggets problem step by step in the BQN programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the NetRexx programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the Forth programming language