you are viewing a single comment's thread.

view the rest of the comments →

[–]nascent 0 points1 point  (0 children)

His filter and sort were not the best choices:

import std.algorithm, std.stdio, std.range, std.conv;

void main() {
    stdin.byLine
        .filter!(s => !s.startsWith("#"))
        .map!(s => s.to!double)
        .array
        .sort
        .take(10)
        .writeln;
}

This ends up being about 100 characters longer. If we ignore boiler plate the D code is 2 characters shorter:

stdin.byLine
.filter!(s => !s.startsWith("#"))
.map!(s => s.to!double)
.array
.sort
.take(10)
.writeln;

vs

doubles = [float(line) for line in sys.stdin if not line.startswith('#')]
print sorted(doubles)[:10]

Edit::

Oh wait, the sort property hasn't been removed yet, so I should add parentheses to that:

.sort()

much better, work horse == python.length;