coin problem loop version