LDC 0.9.2 release candidate
bearophile
bearophileHUGS at lycos.com
Sun Feb 14 10:34:35 PST 2010
Ellery Newcomer:
> And now that I look at it, even dmd generated executables are getting
> their pants wupped by an equivalent python script. Suggestions for a
> more efficient use of tango are welcome.
DMD/D1/Phobos:
import std.stream: BufferedFile;
import std.string: split;
import std.conv: toInt;
import std.stdio: writefln;
T max(T)(T x, T y) { return x >= y ? x : y; }
void main() {
int[][] triangle;
foreach (string line; new BufferedFile("triangle.txt")) {
auto parts = line.split();
auto line_nums = new int[parts.length];
foreach (i, num; parts)
line_nums[i] = toInt(num);
triangle ~= line_nums;
}
while (triangle.length > 1) {
auto last_row = triangle[$ - 1];
for (int i; i < triangle.length - 1; i++)
triangle[$ - 2][i] += max(last_row[i], last_row[i + 1]);
triangle.length = triangle.length - 1;
}
writefln(triangle[0][0]);
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list