Two sum: Difference between revisions
Content added Content deleted
m (→{{header|Visual Basic .NET}}: Fixed typo (compliment → complement)) |
(added MiniScript example) |
||
Line 1,183: | Line 1,183: | ||
</pre> |
</pre> |
||
=={{header|MiniScript}}== |
|||
<lang MiniScript>twoSum = function(numbers, sum) |
|||
// Make a map of values to their indices in the numbers array |
|||
// as we go, so we will know when we've found a match. |
|||
map = {} |
|||
for i in numbers.indexes |
|||
key = sum - numbers[i] |
|||
if map.hasIndex(key) then return [map[key], i] |
|||
map[numbers[i]] = i |
|||
end for |
|||
end function |
|||
print twoSum([0, 2, 11, 19, 90], 21)</lang> |
|||
Output: |
|||
<pre>[1, 3]</pre> |
|||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |