Marketing of D - article topic ideas?

Nick Sabalausky a at a.a
Tue Jun 8 15:51:19 PDT 2010


"Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
news:humfgd$1l7$2 at digitalmars.com...
> On 06/08/2010 04:53 PM, Simen kjaeraas wrote:
>> Simen kjaeraas <simen.kjaras at gmail.com> wrote:
>>
>>> Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote
>>>
>>>> max of n elements is O(n).
>>>
>>> T max( T )( T[] values ) {
>>> T result = values[0];
>>> foreach ( i, e; values[1..$] ) {
>>> if ( max( values[i+1..$] ) > result ) {
>>> result = max( values[i+1..$] );
>>> }
>>> }
>>> return result;
>>> }
>>
>> Better:
>>
>>
>> T max( T )( T[] values ) {
>> if ( values.length == 1 ) {
>> return values[0];
>> } else {
>> return max( values[0..values.length/2] ) > max(
>> values[values.length/2..$] ) ? max( values[0..values.length/2] ) : max(
>> values[values.length/2..$] );
>> }
>> }
>>
>
> I'm not sure I understand the point. Could you please elaborate?
>

He's being a smart-ass and making implementations of max() that are worse 
than O(n) :)

Hee hee. Obfuscation is fun :)




More information about the Digitalmars-d mailing list