Return to Snippet

Revision: 10364
at March 5, 2009 11:20 by marcospereira


Updated Code
import static java.math.BigInteger.ONE

def factorial2(n) {
    (ONE..n).inject(ONE) { result, number -> result*number }
}

def sumDigits(n) {
    n.toString().collect { it.toBigInteger() }.sum()
}

Revision: 10363
at December 22, 2008 10:45 by marcospereira


Initial Code
import static java.math.BigInteger.ONE

def factorial2(BigInteger n) {
    (ONE..n).inject(ONE) { result, number -> result.multiply(number) }
}

def sumDigits(BigInteger n) {
    n.toString().collect { it.toBigInteger() }.sum()
}

Initial URL

                                

Initial Description
A Groovier way to write http://snipplr.com/view/10565/find-the-sum-of-digits-in-100-factorial/

Initial Title
A Groovier Way to Find the sum of digits in 100! (Factorial)

Initial Tags

                                

Initial Language
Groovy