Count coin problem in scala