Coding challenge

Mark Wieder mwieder at ahsoftware.net
Wed Jan 30 23:16:24 EST 2013


Terry-

Wednesday, January 30, 2013, 7:56:49 PM, you wrote:

> OK - I'm usually crap at these things but I'll have a go...

> function getChange pTotal
>    put "50,20,10,5,2,1" into tCoins
>    local tCounts
>    put 0 into tValue
>    repeat for each item tCoin in tCoins
>       put trunc(pTotal/tCoin) into tValue
>       put tValue & space after tCounts
>       subtract tCoin*tValue from pTotal
>    end repeat
>    return tCounts
> end getChange

That'll do it.
Running your implementation I get a number for each coin type.
As in 74 = 1 1 0 0 2 0

-- 
-Mark Wieder
 mwieder at ahsoftware.net





More information about the use-livecode mailing list