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

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 27 11:49:28 PDT 2013


On Thu, 27 Jun 2013 14:37:25 -0400, Timon Gehr <timon.gehr at gmx.ch> wrote:

> int f(int x){ return x?(x&1?x:-x)+(x>0?1:-1):0; }

This is similar to mine, but I like the factoring.

Still needs a special case for f(f(int.max)) which in your function  
returns int.max (like mine).

-Steve


More information about the Digitalmars-d-learn mailing list