Advent of Code

Ola Fosheim Grøstad via Digitalmars-d digitalmars-d at puremagic.com
Wed Dec 9 01:30:28 PST 2015


On Wednesday, 9 December 2015 at 02:48:31 UTC, Sean Campbell 
wrote:
> how is this D speek. it's far shorter and easier to read if you 
> use
> writefln("floor %s",input.count('(') - input.count(')'));

Yes, I don't find chaining of methods all that easy to read 
either, but you can do less work by taking advantage of D already 
knowing the length of the input:

import std.stdio;
import std.algorithm;

void main(){
	immutable input = "(((())";
	immutable long len = input.length - 2*input.count(')');
	writeln(len);
}



More information about the Digitalmars-d mailing list