November 17, 2013
SomeDude:

> I have a task if you are interested, but I didn't bother to login to create it.
> So if you like, you can create the page...

It's better to discuss this in D.learn, where most of Rosettacode matters are discussed. I opened this in the main newsgroup to see if someone was willing to post it to Reddit.


> In a sequence of a million random integers, return the length and the indexes of the longest duplicate sequence (display indexes counting from one, not zero).

If you write a first version of D solution I can post task description and its D solution in the Rosettacode site. I will later make improvements in your code, to make it more uniform with the other entries, etc.


> In order for everybody to start with the same random sequence, it may be useful to specify a simple implementation for the generating function.

What function do you suggest? (It should be possible to implement on 32-64bit systems, in Haskell, in languages with only multi-precision integers, in languages like Ada that give errors on overflows, and in Java without unsigned integers).

Bye,
bearophile
November 17, 2013
SomeDude:

> And so, what are the rules for not using ranges badly ? What should be avoided ?

A newsgroup post is not large enough to contain an answer to this, that requires one or two articles to be written. In general writing quick code is partially an art, with the help of the profiler.

Bye,
bearophile
November 17, 2013
> What function do you suggest? (It should be possible to implement on 32-64bit systems, in Haskell, in languages with only multi-precision integers, in languages like Ada that give errors on overflows, and in Java without unsigned integers).

The Computer Shootout site uses this one:


int nextRandom() nothrow {
    enum int IM = 139968, IA = 3877, IC = 29573;
    __gshared static int last = 42;
    return last = (last * IA + IC) % IM;
}

void main() {
    import std.stdio;

    foreach (i; 0 .. 100) {
        nextRandom.writeln;
    }
}


Bye,
bearophile
1 2 3 4
Next ›   Last »