Anonymous user
Equilibrium index: Difference between revisions
Updated the program to compile with Nim 1.4. Changed slightly the output. Added the output.
(Updated the program to compile with Nim 1.4. Changed slightly the output. Added the output.) |
|||
Line 1,628:
=={{header|Nim}}==
{{trans|Python}}
<lang nim>import math, sequtils, strutils
iterator eqindex(data: openArray[int]): int =
var suml, ddelayed = 0
var sumr = sum(data)
Line 1,639:
if suml == sumr:
yield i
const d = @[@[-7, 1, 5, 2, -4, 3, 0],
@[2, 4, 6],
@[2, 9, 2],
@[1, -1, 1, -1, 1, -1, 1]]
for data in d:▼
echo "d = [", data.join(", "), ']'
echo "eqIndex(d) -> [", toSeq(eqindex(data)).join(", "), ']'</lang>
{{out}}
▲for data in d:
<pre>d =
d = [2, 4, 6]
eqIndex(d) -> []
d = [2, 9, 2]
eqIndex(d) -> [1]
d = [1, -1, 1, -1, 1, -1, 1]
eqIndex(d) -> [0, 1, 2, 3, 4, 5, 6]</pre>
=={{header|Objeck}}==
|