Let's Play Code Golf

Chris Williams via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 24 14:54:20 PST 2015


On Monday, 23 February 2015 at 22:58:22 UTC, Charles wrote:
>> I didn't beat your score, but I did it with ranges (full 
>> character count was 174):
>>
>> stdin.readln();
>> foreach(x; stdin.byLine)
>>    writefln("%0.15f", map!(a => 
>> (a&1?-1:1)/(2.0*a+1))(iota(x.to!int)).sum);
>>
>> I think if I didn't have to import so many things, I would 
>> have done much better :)
>>
>> -Steve
>
> Yeah, imports were my issue too. Especially with readln, 
> because using that meant I needed std.conv. Why don't reals 
> initialize to zero? That'd save me 4 characters! :P

For real programming purposes, having floating types initialize 
to an invalid state helps developers to catch logic errors that 
allow a variable to go into a mathematical operation without 
having been initialized.


More information about the Digitalmars-d mailing list