wc in D: 712 Characters Without a Single Branch

Petar Petar
Tue Jan 28 21:40:40 UTC 2020


On Tuesday, 28 January 2020 at 14:01:35 UTC, Mike Parker wrote:
> [snip]

BTW, while playing with a solution of my own [0] I noticed that 
both mine and Robert's version return different results for the 
following input [1]:

>       expected: 
> '\u0003\u0000\u0000\u00005èÆÕL]\u0012|Î¾ž\u001a7«›\u00052\u0011(ЗY\n<\u0010\u0000\u0000\u0000\u0000\u0000\u0000e!ßd/ñõì\f:z¦Î¦±ç·÷Í¢Ëß\u00076*
\bŽ—ñžùC1ÉUÀé2\u001aÓ†BŒ' },

To reproduce:

$ curl -fsSL 
https://github.com/ethjs/ethjs-util/raw/e9aede668177b6d1ea62d741ba1c19402bc337b3/src/tests/test.index.js | sed '350q;d' > input

$ ./robert input
1 4 190 input

$ wc -lwm input
   1   3 190 input

[0]:

> import std.algorithm : count, splitter;
> import std.stdio : File, writefln;
> import std.typecons : Yes;
>
> void main(string[] args) {
>     size_t lines, words, bytes;
>     foreach (line; args[1].File.byLine(Yes.keepTerminator)) {
>         lines++;
>         bytes += line.count;
>         words += line.splitter.count;
>     }
>     writefln!"%u %u %u %s"(lines, words, bytes, args[1]);
> }

[1]: 
https://github.com/ethjs/ethjs-util/blob/e9aede668177b6d1ea62d741ba1c19402bc337b3/src/tests/test.index.js#L350


More information about the Digitalmars-d-announce mailing list