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
  • C# to D Dennis Ritchie via Digitalmars-d-learn

Reply via email to