Skip to content

Instantly share code, notes, and snippets.

@jessex
Created March 4, 2011 18:46
Show Gist options
  • Save jessex/855478 to your computer and use it in GitHub Desktop.
Save jessex/855478 to your computer and use it in GitHub Desktop.
Euler Problem 029
//Maps all a^b terms for lower <= b <= upper to all a for lower <= a <= upper
def getDistinctCount(lower:Int, upper:Int) = {
(lower to upper).flatMap(a => (lower to upper).map(b => BigInt(a).pow(b)))
.distinct.size //Return number of distinct elements
}
println(getDistinctCount(2, 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment