On Friday, 22 May 2015 at 00:23:30 UTC, Dennis Ritchie wrote:
Hi,
I've collected some of Python's features. It seems to me that
they are not in the D!
Surely all this is in the D? :)
http://rextester.com/CNQQR3333
import std.algorithm;
import std.range;
import std.stdio;
import std.conv;
void main() {
enum n1 = 5;
writeln(stdin.byLine
.map!(line => line.split(" ").map!(x => to!int(x)))
);
writeln("------");
enum n2 = 6;
writeln(iota(n2)
.map!(i => chain(
repeat("2", i),
only("1"),
repeat("0", n2 - i - 1),
only("\n")
).joiner(" ")).joiner
);
}
(I omitted evens/odds because it's been addressed and fizzbuzz
because there's probably dozens of them floating around)
You seem to be focusing on D's arrays only, but the real meat is
in ranges, which are more generic. Also note that the above
solution doesn't allocate any of the ranges in the heap; they're
all on the stack (as opposed to Python, where you have to
allocate lists or use iterators+itertools).