June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
66
Task/Equilibrium-index/Elena/equilibrium-index.elena
Normal file
66
Task/Equilibrium-index/Elena/equilibrium-index.elena
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import extensions.
|
||||
import system'routines.
|
||||
import system'collections.
|
||||
import extensions'routines.
|
||||
|
||||
class EquilibriumEnumerator :: Enumerator
|
||||
{
|
||||
int left.
|
||||
int right.
|
||||
int index.
|
||||
enumerator en.
|
||||
|
||||
multi constructor new : object
|
||||
<= new enumerator:object.
|
||||
|
||||
constructor new(Enumerator en)
|
||||
[
|
||||
@en := en.
|
||||
|
||||
$self reset.
|
||||
]
|
||||
|
||||
constructor new(BaseEnumerable list)
|
||||
<= new(list enumerator).
|
||||
|
||||
bool next
|
||||
[
|
||||
index += 1.
|
||||
|
||||
while(en next)
|
||||
[
|
||||
var element := en get.
|
||||
right -= element.
|
||||
bool found := (left == right).
|
||||
left += element.
|
||||
|
||||
if (found)
|
||||
[
|
||||
^ true
|
||||
].
|
||||
|
||||
index += 1.
|
||||
].
|
||||
|
||||
^ false
|
||||
]
|
||||
|
||||
reset
|
||||
[
|
||||
en reset.
|
||||
|
||||
left := 0.
|
||||
right := en summarize.
|
||||
index := -1.
|
||||
|
||||
en reset.
|
||||
]
|
||||
|
||||
get = index.
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
EquilibriumEnumerator new:(-7, 1, 5, 2, -4, 3, 0);
|
||||
forEach:printingLn.
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue