Skip to main content
deleted 2 characters in body
Source Link

D: 4645 Characters

T f(T)(T n){return n ==< 12 ? 1 : n * f(n - 1);}

More legibly:

T f(T)(T n)
{
    return n ==< 12 ? 1 : n * f(n - 1);
}

A cooler (though longer version) is the templatized one which does it all at compile time (64 characters):

template F(int n){static if(n<2)enum F=1;else enum F=n*F!(n-1);}

More legibly:

template F(int n)
{
    static if(n < 2)
        enum F = 1;
    else
        enum F = n * F!(n - 1);
}

Eponymous templates are pretty verbose though, so you can't really use them in code golf very well. D's already verbose enough in terms of character count to be rather poor for code golf (though it actually does really well at reducing overall program size for larger programs). It's my favorite language though, so I figure that I might as well try and see how well I can get it to do at code golf, even if the likes of GolfScript are bound to cream it.

D: 46 Characters

T f(T)(T n){return n == 1 ? 1 : n * f(n - 1);}

More legibly:

T f(T)(T n)
{
    return n == 1 ? 1 : n * f(n - 1);
}

A cooler (though longer version) is the templatized one which does it all at compile time (64 characters):

template F(int n){static if(n<2)enum F=1;else enum F=n*F!(n-1);}

More legibly:

template F(int n)
{
    static if(n < 2)
        enum F = 1;
    else
        enum F = n * F!(n - 1);
}

Eponymous templates are pretty verbose though, so you can't really use them in code golf very well. D's already verbose enough in terms of character count to be rather poor for code golf (though it actually does really well at reducing overall program size for larger programs). It's my favorite language though, so I figure that I might as well try and see how well I can get it to do at code golf, even if the likes of GolfScript are bound to cream it.

D: 45 Characters

T f(T)(T n){return n < 2 ? 1 : n * f(n - 1);}

More legibly:

T f(T)(T n)
{
    return n < 2 ? 1 : n * f(n - 1);
}

A cooler (though longer version) is the templatized one which does it all at compile time (64 characters):

template F(int n){static if(n<2)enum F=1;else enum F=n*F!(n-1);}

More legibly:

template F(int n)
{
    static if(n < 2)
        enum F = 1;
    else
        enum F = n * F!(n - 1);
}

Eponymous templates are pretty verbose though, so you can't really use them in code golf very well. D's already verbose enough in terms of character count to be rather poor for code golf (though it actually does really well at reducing overall program size for larger programs). It's my favorite language though, so I figure that I might as well try and see how well I can get it to do at code golf, even if the likes of GolfScript are bound to cream it.

Source Link

D: 46 Characters

T f(T)(T n){return n == 1 ? 1 : n * f(n - 1);}

More legibly:

T f(T)(T n)
{
    return n == 1 ? 1 : n * f(n - 1);
}

A cooler (though longer version) is the templatized one which does it all at compile time (64 characters):

template F(int n){static if(n<2)enum F=1;else enum F=n*F!(n-1);}

More legibly:

template F(int n)
{
    static if(n < 2)
        enum F = 1;
    else
        enum F = n * F!(n - 1);
}

Eponymous templates are pretty verbose though, so you can't really use them in code golf very well. D's already verbose enough in terms of character count to be rather poor for code golf (though it actually does really well at reducing overall program size for larger programs). It's my favorite language though, so I figure that I might as well try and see how well I can get it to do at code golf, even if the likes of GolfScript are bound to cream it.