Return to Snippet

Revision: 10318
at December 18, 2008 13:03 by theobriscoe


Initial Code
def factorial2(BigInteger n){
    BigInteger answer = BigInteger.ONE;

    for (int i=1; i<=n; i++) {
        answer = answer.multiply(BigInteger.valueOf(i));
    }
    return answer
}

def sumDigits(BigInteger n){
    def digitString = n.toString();
    def digitArray = []
  
    digitString.each{ i ->
        digitArray.add( i.toBigInteger() )
    }
    return digitArray.sum()
}

Initial URL

                                

Initial Description
Find the sum of digits in 100!
n! means n × (n − 1) × ... × 3 × 2 × 1

Initial Title
Find the sum of digits in 100! (Factorial)

Initial Tags

                                

Initial Language
Groovy