title: coin change algorithm in scala using recursion
body: <p>I am trying to program the coin change problem in Scala using recursion. The code that i have written is as follows.</p>
  
  <pre><code>def countChange(money: Int, coins: List[Int]): Int = {
    def ways(change: List[Int], size: Int, capacity: Int): Int = {
      if(capacity == 0) 1
      if((capacity &lt; 0) || (size &lt;= 0)) 0
  
      //println and readLine to check and control each recursive call.
  
      println("calling ways(",change, change.length-1, capacity,") + ways(",change,   change.length, capacity - change(change.length - 1),")")
      readLine()
      //
  
      ways(change, change.length-1, capacity) + ways(change, change.length, capacity - change(change.length - 1))
    }
    ways(coins, coins.length, money)
  }
  </code></pre>
  
  <p>On running the code, it does not terminate and keeps on calling the first recursive call. Where am I going wrong?</p>