Let's Play Code Golf
bearophile via Digitalmars-d
digitalmars-d at puremagic.com
Mon Feb 23 16:03:52 PST 2015
Steve Sobel:
> It can get down to 155 using ranges, but those imports really
> are killer.
You usually don't want to design a language for code golfing (but
several exist, like http://esolangs.org/wiki/GolfScript ).
> void main(){import
> std.algorithm,std.conv,std.range,std.stdio;foreach(n;stdin.byLine.drop(1))writefln("%.15f",iota(n.to!int).map!"(-1.0)^^a/(2*a+1)".sum);}
You can remove one char:
iota(n.to!int).
n.to!int.iota.
Bye,
bearophile
More information about the Digitalmars-d
mailing list