Posted By

marcospereira on 12/22/08


Tagged

factorial sum bigdecimal idiomatic


Versions (?)

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


 / Published in: Groovy
 

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

  1. import static java.math.BigInteger.ONE
  2.  
  3. def factorial2(n) {
  4. (ONE..n).inject(ONE) { result, number -> result*number }
  5. }
  6.  
  7. def sumDigits(n) {
  8. n.toString().collect { it.toBigInteger() }.sum()
  9. }

Report this snippet  

You need to login to post a comment.