Advent of Code
Sean Campbell via Digitalmars-d
digitalmars-d at puremagic.com
Tue Dec 8 18:48:31 PST 2015
On Wednesday, 2 December 2015 at 08:45:11 UTC, Adrian Matoga
wrote:
> On Wednesday, 2 December 2015 at 03:50:20 UTC, Charles wrote:
> (..)
>>
>> auto input = "arbitrarily long string of '(' and ')'";
>>
>> int floor;
>> foreach(movement; input)
>> floor += (movement == '(' ? 1 : -1);
>>
>> writeln(floor);
>
> Speak D to me, please.
> stdin.byLine.front.map!(a => a.predSwitch('(', 1, ')', -1,
> 0)).sum.writeln;
how is this D speek. it's far shorter and easier to read if you
use
writefln("floor %s",input.count('(') - input.count(')'));
More information about the Digitalmars-d
mailing list