http://d.puremagic.com/issues/show_bug.cgi?id=4705
--- Comment #5 from bearophile_h...@eml.cc 2011-01-01 06:33:02 PST --- Another example to show why a better max() is useful. The task is ot show how the number less than 1000 which has the longest hailstone sequence. For the hailstone see: http://en.wikipedia.org/wiki/Collatz_conjecture The code, DMD 2.051: import std.stdio, std.algorithm, std.range, std.typecons; auto hailstone(int n) { auto result = [n]; while (n != 1) { n = n & 1 ? n*3 + 1 : n/2; result ~= n; } return result; } void main() { auto r = reduce!max(map!((i){return tuple(hailstone(i).length, i);})(iota(1, 1000)))[1]; writeln(r); } With a max that supports a key function and iterables the line of code in the main() becomes just: auto r = max!hailstone(iota(1, 1000)); With the enhancement request 5395 it becomes even more readable: auto r = max!hailstone(1 .. 1000); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------