[ create a new paste ] login | about

Link: http://codepad.org/9NDDLOZ2    [ raw code | fork ]

D, pasted on May 3:
--------------------------------------

D V.2 implementation:
Compile with: dmd -O -release -inline


import std.stdio, std.algorithm;

void main() {
    int[string] hash;
    int fmax;
    foreach (line; stdin.byLine())
        fmax = max(fmax, ++hash[cast(string)line]);
    writeln(hash.length, "\t", fmax);
}

--------------------------------------

Or even this, a bit slower (D V.2 implementation):
Compile with: dmd -O -release -inline


import std.stdio, std.algorithm;

void main() {
    int[string] H;
    foreach (line; stdin.byLine())
        H[cast(string)line]++;
    writeln(H.length, "\t", reduce!max(H.byValue));
}

--------------------------------------

D v.1 code with Phobos
Compile with: dmd -O -release -inline


import std.stdio;

void main() {
    int[char[]] hash;
    char[] line;
    int max;
    while (readln(stdin, line)) {
        int current = ++hash[line];
        max = (current > max) ? current : max;
    }
    writefln(hash.length, "\t", max);
}

--------------------------------------

D v.1 code with Phobos. Here I have kept your line counter.
More up to date versions of GDC too may not have that bug.
Compile (probably) with: gdc -O3 -frelease -inline hash.d -o hash


import std.stdio, std.conv;

void main(string[] args) {
    int N = (args.length >= 2) ? toInt(args[1]) : 5_000_000;

    int[char[]] hash;
    char[] line;
    int max, count;
    while (readln(stdin, line)) {
        int current = ++hash[line];
        max = (current > max) ? current : max;

        if (++count == N) {
            writefln(hash.length, "\t", max);
            break;
        }
    }
}

--------------------------------------


Create a new paste based on this one


Comments: