On Wednesday, 26 June 2013 at 22:43:05 UTC, David wrote:
Am 26.06.2013 22:51, schrieb Gary Willoughby:
I solved it ;)

http://dpaste.dzfl.pl/5cd56e9d

Yes, but "maybe" the interviewer is waiting just one function, since the question was: "Design a function f". So I rewrote your example:

import std.stdio;
import std.string;

auto f(T)(T n){
        if(is(T==float))
                return cast(int)n;
        
        return cast(float)-n;
}

void main() {
        foreach(n; int.min..int.max) {
                assert(f(f(n)) == -n);
        }
}

Again, in the same way, maybe the interviewer want "n" as 32 signed int not a auto/template etc. :D

Reply via email to