How would you solve this 'interview' question in D?

John Colvin john.loughran.colvin at gmail.com
Thu Jun 27 09:02:56 PDT 2013


On Thursday, 27 June 2013 at 15:32:05 UTC, MattCodr wrote:
> On Thursday, 27 June 2013 at 12:38:25 UTC, John Colvin wrote:
>> The question is ambiguous as to what they mean by -n. Do they 
>> mean the result of negation on the 32bit signed int, or do 
>> they mean the negative of the number represented by that int. 
>> this matters because -int.min evaluates to int.min due to 
>> wraparound.
>
> From: February 11, 2008:
>
> Vlad Patryshev said...
>
> ...Write a function f on 32-bit integers that, applied twice, 
> it negates the integer. f(f(n)) = -n.
>
> Source: 
> http://steve-yegge.blogspot.com.br/2008/02/portrait-of-n00b.html
>
> Matheus.

How is that any more specific?


More information about the Digitalmars-d-learn mailing list