Skip to content

Instantly share code, notes, and snippets.

@tyrcho
Created October 14, 2013 15:41
Show Gist options
  • Save tyrcho/6977684 to your computer and use it in GitHub Desktop.
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)
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