scala-basic: elegant solution of countChange