uris77
8/23/2013 - 5:07 AM

paren.scala

def balance(chars: List[Char]): Boolean = {
    def hasRight(remainingList: List[Char]): Boolean = {
      if(remainingList.isEmpty)
        false
      else    	  
          remainingList.head match {
          	case ')' => if(remainingList.tail.isEmpty) true else balance(remainingList.tail)
          	case '(' => hasRight(remainingList.tail)
          	case _ => true
      }
    }
    
    if (chars.isEmpty) 
      true 
    else      
      chars.head match {
      	case '(' => hasRight(chars.tail)
      	case ')' => false
      	case _ =>  balance(chars.tail)      
    }
       
  }