Two sum: Difference between revisions
Content added Content deleted
(→version 2: updated the REXX program to handle the latest task requirements/specifications, used a template for the output, added a solution count (and message), added an aligned summation, indicated that solution contains (zero based) indices.) |
(Realize in F#) |
||
Line 384: | Line 384: | ||
</pre> |
</pre> |
||
=={{header|F_Sharp|F#}}== |
|||
<lang fsharp> |
|||
// Two Sum : Nigel Galloway December 5th., 2017 |
|||
let fN n i = |
|||
let rec fN n e = |
|||
match n with |
|||
|n::g when n < i -> match List.mapi(fun g i-> (n,i,g)) g |> List.tryFind(fun (n,g,l)->(n+g)=i) with |
|||
|Some (n,g,l) -> [e;e+l+1] |
|||
|_ -> fN g (e+1) |
|||
|_ -> [] |
|||
fN n 0 |
|||
printfn "%A" (fN [0; 2; 11; 19; 90] 101) |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
[1; 3] |
|||
</pre> |
|||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|Gforth|0.7.3}} |
{{works with|Gforth|0.7.3}} |