On Tue, Jul 10, 2012 at 3:35 AM, Jacob Carlborg <span dir="ltr"><<a href="mailto:doob@me.com" target="_blank">doob@me.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 2012-07-10 08:59, Dmitry Olshansky wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Can you do it in other languages?<br>
</blockquote>
<br></div>
Sure, in Ruby, but that only works on arrays:<br>
<br>
p [5, 3, 5, 6, 8].uniq.map{ |e| e.to_s }.sort<br>
<br>
Prints:<br>
<br>
["3", "5", "6", "8"]<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
/Jacob Carlborg<br>
</font></span></blockquote></div><br><div>For what it's worth:</div><div><br></div><div><div>    e = 10_000_000</div><div>    a = ((1..e).to_a + (1..e).to_a).sort.uniq.map{ |e| e }</div><div><br></div></div><div>Runs in 21,320 ms on my machine with Ruby 1.9.3 whereas:</div>
<div><br></div><div><div>    auto end = 10_000_000;</div><div>    auto a = chain(iota(1, end), iota(1, end)).array()</div><div>                .sort()</div><div>                .uniq()</div><div>                .map!(n=>n).array();</div>
</div><div><br></div><div>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).</div>
<div><br></div><div>Regards,</div><div>Brad Anderson</div>