Skip to content

Instantly share code, notes, and snippets.

@hueitan

hueitan/trailing_zero.md

Last active Aug 29, 2015
Embed
What would you like to do?
trailing zero problem (superfactorial) - https://codefights.com/feed/ZKW6FzW8Rjj9wTLWo
function superfactorialZeros(N) {
    var result = 0;
    for (i = 1; i <= N; i++) {
        result += zeroes(i);
    }

    return result;
}

function zeroes(n) {
    var i = 1;
    var result = 0;
    while (n >= i) {
        i *= 5;
        result += Math.floor(n / i);
    }
    return result;
}

// alternative of zeroes
var zeroes = function z(n)  {
    k = n/5 | 0
    return k ? k + f(k) : 0
}
// or
function zeroes (n) {
     s = 0
     while (n/=5) s += n|0
     return s
}

79 char

function superfactorialZeros(N) {
    R = 0

    for (; N ; N--)
        for (j = 5; N >= j; j *= 5) 
            R += N / j | 0
        
    return R
}

76 char

function superfactorialZeros(N) {
    R = 0

	while (n=N--)
        while(n>=5)
            R += (n/=5)|0
        
    
    return R
}

well... 71 cahr

function superfactorialZeros(N) {
    R = 0

    while (j = N--)
        while (j /= 5)
            R += j & j

    return R
}
@hueitan

This comment has been minimized.

Copy link
Owner Author

@hueitan hueitan commented May 6, 2015

Really learn a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.