Skip to content

@dbousamra /gist:4653938
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
object Challenge119Easy {
def change(amount: Double) = {
val coins = Map[Int, String](25 -> "Quarter", 10 -> "Dime", 5 -> "Nickel", 1 -> "Penny")
def recurse(m: Int, cs: List[Int] = coins.keys.toList): List[Int] = cs match {
case Nil => Nil
case x :: rs => List.fill(m/x)(x) ::: recurse(m % x, rs)
}
val result = recurse((amount*100).toInt)
coins.filterKeys(k => result.contains(k))
.map { case (k, v) => v + "s: " + result.count(_ == k)}
.mkString("\n")
}
def main(args: Array[String]) = println(change(1.23))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.