Last active
October 12, 2015 18:48
-
-
Save kazua/4071492 to your computer and use it in GitHub Desktop.
Project Euler Problem 21
This file contains 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
//http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2021 | |
//K.A | |
object problem21 { | |
def calcAmicable(acl : Int, xs : List[Int]) : Int = xs match { | |
case Nil => acl | |
case y :: ys => { | |
val divisora = (Range(1,y + 1).toList.filter(y % _ == 0).sum - y) | |
calcAmicable(acl + (if (Range(1, divisora + 1).toList.filter(divisora % _ == 0).sum - divisora == y && divisora != y) divisora else 0), ys) | |
} | |
} | |
def problem21(is : Int) : Int = { | |
calcAmicable(0, Range(1,is).toList) | |
} | |
def main(args : Array[String]) { | |
val problem21k = problem21 _ | |
println(problem21k(10000)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment