Last active
August 29, 2015 14:13
-
-
Save chidakiyo/cd16c4509b8989e5f196 to your computer and use it in GitHub Desktop.
硬貨における強制通用力の上限(社内研修)
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
object LegalTender extends App { | |
val yenCoins = List(1, 5, 10, 50, 100, 500) | |
implicit val yenMax = 20 // デフォルト値定義してるのでコレをコメントアウトしても動く | |
implicit class Coin(x: Int) { | |
def rcptMax(implicit max: Int = 20) = { x * max } | |
} | |
val sumCoins = (coins: List[Int]) => Option(coins map (_ rcptMax) sum) | |
sumCoins(yenCoins).foreach(println) // 13320 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🐯