Two sum: Difference between revisions
Content added Content deleted
(Realize in F#) |
|||
Line 392: | Line 392: | ||
|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 |
|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] |
|Some (n,g,l) -> [e;e+l+1] |
||
|_ -> fN g (e+1) |
|_ -> fN g (e+1) |
||
|_ -> [] |
|_ -> [] |
||
fN n 0 |
fN n 0 |
||
printfn "%A" (fN [0; 2; 11; 19; 90] |
printfn "%A" (fN [0; 2; 11; 19; 90] 21) |
||
</lang> |
</lang> |
||
{{out}} |
{{out}} |
||
Line 401: | Line 401: | ||
[1; 3] |
[1; 3] |
||
</pre> |
</pre> |
||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|Gforth|0.7.3}} |
{{works with|Gforth|0.7.3}} |