On Tue, Jul 10, 2012 at 3:35 AM, Jacob Carlborg <d...@me.com> wrote:

> On 2012-07-10 08:59, Dmitry Olshansky wrote:
>
>  Can you do it in other languages?
>>
>
> Sure, in Ruby, but that only works on arrays:
>
> p [5, 3, 5, 6, 8].uniq.map{ |e| e.to_s }.sort
>
> Prints:
>
> ["3", "5", "6", "8"]
>
> --
> /Jacob Carlborg
>

For what it's worth:

    e = 10_000_000
    a = ((1..e).to_a + (1..e).to_a).sort.uniq.map{ |e| e }

Runs in 21,320 ms on my machine with Ruby 1.9.3 whereas:

    auto end = 10_000_000;
    auto a = chain(iota(1, end), iota(1, end)).array()
                .sort()
                .uniq()
                .map!(n=>n).array();

Runs in 3,057ms with DMD 2.059.  I believe they are largely equivalent but
there is probably room for improvement on both.  I removed to_s/to!string
because I didn't want it allocation bound since we are talking about
algorithm and not the GC or string conversion (with string conversion the
numbers are 28,646ms for Ruby and 14,113ms for D).

Regards,
Brad Anderson

Reply via email to