how to count number of letters with std.algorithm.count / std.algorithm.reduce / std.algorithm.map ?
bearophile
bearophileHUGS at lycos.com
Fri Nov 16 08:37:55 PST 2012
Simen Kjaeraas:
> There. Now it works, and returns a Tuple!(ulong,ulong)(8, 8).
>
> One thing I think is ugly in my implementation is acc + (seq ==
> 'G'). This
> adds a bool and a ulong together. For more points, replace that
> with
> acc + (seq == 'G' ? 1 : 0).
I use a pragmatic approach: I use such higher order functions
when they give me some advantage, like more compact code, or
less-bug-prone code, etc (because they usually don't give me
faster code). In this case a normal loop that increments two
counters is faster and far more easy to read and understand :-)
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list