Two sum: Difference between revisions

Content added Content deleted
No edit summary
Line 1,296: Line 1,296:
The numbers with indices 1 and 3 sum to 21
The numbers with indices 1 and 3 sum to 21
</pre>
</pre>

=={{header|Liberty BASIC}}==
<lang liberty basic>myArray(0) = 0
myArray(1) = 2
myArray(2) = 11
myArray(3) = 19
myArray(4) = 90

sum = 21

Print twoToSum$("myArray", sum, 0, 4)
End

Function twoToSum$(arrayName$, targetSum, minElement, maxElement)
i = minElement : j = maxElement
While (i < j)
Select Case
Case (Eval(arrayName$;"(";i;")") + Eval(arrayName$;"(";j;")")) < targetSum
i = (i + 1)
Case (Eval(arrayName$;"(";i;")") + Eval(arrayName$;"(";j;")")) > targetSum
j = (j - 1)
Case Else
twoToSum$ = "[";i;",";j;"]"
Exit Function
End Select
Wend
twoToSum$ = "[]"
End Function</lang>
{{out}}
<pre>[1,3]</pre>


=={{header|Lua}}==
=={{header|Lua}}==