Last active
November 20, 2016 13:49
-
-
Save filipevarjao/72821d0c4e8dada85184629678f0c6f7 to your computer and use it in GitHub Desktop.
Equilibrium index of a array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -module(equi). | |
| -export([start/1]). | |
| -spec start([any()]) -> integer(). | |
| start(Array) -> | |
| check_equi([], Array, 0). | |
| -spec check_equi([any()], [any()], non_neg_integer()) -> integer(). | |
| check_equi(_, [], _) -> -1; | |
| check_equi(PreList, [Head|Tail], EquIndice) -> | |
| case lists:sum(PreList) == lists:sum(Tail) of | |
| true -> | |
| EquIndice; | |
| false -> | |
| check_equi([Head|PreList], Tail, EquIndice + 1) | |
| end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment