Return to Snippet

Revision: 10365
at December 22, 2008 11:45 by marcospereira


Initial Code
import static java.math.BigInteger.ONE

def factorial2(BigInteger n) {

    def answer = ONE

    for (i=BigInteger.ONE; i<=n; i++) {
        answer *= i
    }

    return answer
}

def sumDigits(BigInteger n) {

    def digitString = n.toString()
    def digits = digitString.collect { it.toBigInteger() }

    return digits.sum()

}

Initial URL


Initial Description


Initial Title
Find the sum of digits in 100! (Factorial): A little more groovier

Initial Tags


Initial Language
Groovy