Last active
September 22, 2016 18:41
-
-
Save dholbrook/6442284 to your computer and use it in GitHub Desktop.
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
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