Two sum: Difference between revisions
Content added Content deleted
m (→ES6) |
m (→ES6: Minor simplification) |
||
Line 244: | Line 244: | ||
// summingPairIndices :: -> Int -> [Int] -> [(Int, Int)] |
// summingPairIndices :: -> Int -> [Int] -> [(Int, Int)] |
||
let summingPairIndices = (n, xs) => |
let summingPairIndices = (n, xs) => |
||
concatMap((x, ix) => concatMap((y, iy) => |
concatMap((x, ix) => concatMap((y, iy) => |
||
iy > ix ? [] : ( // Ignoring mirror image tuples |
|||
x + y === n ? [ |
x + y === n ? [ |
||
[iy, ix] |
[iy, ix] |
||
] : [] |
] : [] |
||
) |
), xs), xs); |
||
}, xs), xs); |
|||
return summingPairIndices(21, [0, 2, 11, 19, 90]); |
return summingPairIndices(21, [0, 2, 11, 19, 90]); |