Two sum: Difference between revisions

Added EasyLang implementation
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(Added EasyLang implementation)
Line 717:
(1,3)
</pre>
 
=={{header|EasyLang}}==
EasyLang arrays are one-based, so the indices returned are also one-based.
<syntaxhighlight lang="easylang">
func twoSum sum . array[] pair[] .
i = 1
j = len array[]
# The array remains empty if no sum is found
pair[] = [ ]
repeat
if array[i] + array[j] = sum
pair[] = [ i j ]
break 2
elif array[i] + array[j] > sum
j -= 1
elif array[i] + array[j] < sum
i += 1
.
until i = j
.
.
numbers[] = [ 0 2 11 19 90 ]
call twoSum 21 numbers[] pair[]
print "[" & pair[1] & ", " & pair[2] & "]"
</syntaxhighlight>
{{out}}
<pre>[2, 4]</pre>
 
=={{header|Elixir}}==
<syntaxhighlight lang="elixir">defmodule RC do
175

edits