Skip to content

Instantly share code, notes, and snippets.

@dholbrook
Last active September 22, 2016 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dholbrook/6442284 to your computer and use it in GitHub Desktop.
Save dholbrook/6442284 to your computer and use it in GitHub Desktop.
package euler
object Euler21 extends App {
def properDivisors(n: Int): Seq[Int] =
(1 to n / 2).filter(n % _ == 0)
val dn = for {n <- 0 until 10000} yield properDivisors(n).sum
private def isAmicable(n: Int, i: Int): Boolean =
n < 10000 && dn(n) == i && dn(n) != n
val r = (for {
(n, i) <- dn.zipWithIndex if isAmicable(n, i)
} yield n).sum
println(r)
assert(r == 31626)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment