Created
October 14, 2013 15:41
-
-
Save tyrcho/6977684 to your computer and use it in GitHub Desktop.
Display the groups of friend numbers (which have the same sum of divisors)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object FriendNumbers extends App { | |
def sumOfDivisors(n: Int) = | |
(for { | |
i <- 1 to Math.sqrt(n).toInt | |
if n % i == 0 | |
} yield i + n / i).sum | |
val friendGroups = (1 to 10000).groupBy(sumOfDivisors).filter(_._2.size > 1).toList.sortBy(_._1) | |
println(friendGroups) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment