Skip to content

Instantly share code, notes, and snippets.

@jaredcacurak
Created February 24, 2011 02:18
Show Gist options
  • Save jaredcacurak/841629 to your computer and use it in GitHub Desktop.
Save jaredcacurak/841629 to your computer and use it in GitHub Desktop.
A Groovy solution for Project Euler - Problem 30
Integer.metaClass.toDigits = {
value.toString().toList().collect { it as Integer }
}
Integer.metaClass.digitsToThePowerOf = { power ->
toDigits().collect { it ** power }
}
(1000..200000).inject 0, { sum, number ->
sumOfDigitsToTheFifthPower = number.digitsToThePowerOf(5).sum()
sum += (number == sumOfDigitsToTheFifthPower) ? number : 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment