Created
June 23, 2013 15:01
-
-
Save kazua/5845326 to your computer and use it in GitHub Desktop.
Project Euler Problem 31
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
| //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