Simple algorithm to count number of coins