Two sum: Difference between revisions

(→‎{{header|zkl}}: another solution)
(→‎{{header|zkl}}: sort arrays)
Line 80:
 
=={{header|zkl}}==
I think this is O(n!), The double loop solution is O(n^2). These two solutions don't care if the array is sorted
<lang zkl>fcn twoSum(sum,ns){
Utils.Helpers.combosKW(2,ns).filter('wrap([(a,b)]){ a+b==sum }) // lazy combos
Line 92:
rs
}</lang>
<lang zkl>twoSum(21,T(0,2,11,19,90,21,90)).println();
twoSum(25,T(0,2,11,19,90,21,90)).println();</lang>
{{out}}
<pre>
L(L(0,54),L(1,3))
L()
</pre>
Anonymous user