Convert little imperative code to functional coding style

bioinfornatics bioinfornatics at fedoraproject.org
Sat Aug 11 12:05:10 PDT 2012


Le vendredi 10 août 2012 à 20:26 +0200, Timon Gehr a écrit :
> Is this what you are looking for?
> 
> import std.stdio;
> import std.range        : iota;
> import std.algorithm    : map, filter, joiner;
> import std.typecons     : tuple;
> import std.math         : sqrt, floor;
> 
> void main(){
>      immutable limit = cast(size_t)floor(sqrt(1_000.0));
> 
>      auto r = iota(2,limit).map!(m=>iota(1,m-1).map!(n=>tuple(m,n))).joiner
>              .filter!(t=>2*t[0]*(t[0]+t[1])==1_000)
>              .map!(t=>(t[0]^^4-t[1]^^4)*(2*t[0]*t[1]));
> 
>      writeln(r.front);
> }
> 

oh yes beautiful thanks



More information about the Digitalmars-d-learn mailing list