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

MattCodr mattcodr at hotmail.com
Thu Jun 27 08:32:02 PDT 2013


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.


More information about the Digitalmars-d-learn mailing list