Skip to content

Instantly share code, notes, and snippets.

@kazua
Created June 23, 2013 15:01
Show Gist options
  • Save kazua/5845326 to your computer and use it in GitHub Desktop.
Save kazua/5845326 to your computer and use it in GitHub Desktop.
Project Euler Problem 31
//http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2031
//write kazua
object problem31 {
val coinlist = List(1, 2, 5, 10, 20, 50, 100, 200)
def getCoinComb(cl : List[Int], ta : Int, ac : Int) : Int = cl match {
case h :: t if h + ac > ta => 0
case h :: t if h + ac == ta => 1
case h :: t => getCoinComb(cl, ta, ac + h) + getCoinComb(t, ta, ac)
case nil => 0
}
def main(args : Array[String]) {
println(getCoinComb(coinlist, 200, 0))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment