C# to D
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 25 12:01:42 PDT 2015
Dennis Ritchie:
> int[] arr = { 7, 5, 7, 3, 3, 5, 3, 3, 0, 3, 1, 1, 5, 1,
> 1, 1, 2, 2, 8, 5, 8, 8 };
> Console.WriteLine(string.Join(" ",
> arr.OrderByDescending(x => arr.Count(y => y == x)).ThenBy(x =>
> x)));
> // prints 1 1 1 1 1 3 3 3 3 3 5 5 5 5 8 8 8 2 2 7 7 0
One solution:
void main() {
import std.stdio, std.algorithm, std.typecons;
auto arr = [7, 5, 7, 3, 3, 5, 3, 3, 0, 3, 1, 1, 5, 1, 1, 1,
2, 2, 8, 5, 8, 8];
arr
.schwartzSort!(x => tuple(-arr.count!(y => y == x), x))
.writeln;
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list