Coding challenge
Terry Judd
terry.judd at unimelb.edu.au
Wed Jan 30 22:56:49 EST 2013
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
Terry...
On 31/01/2013, at 02:16 PM, Mark Wieder wrote:
> Today's algorithm challenge:
>
> Determine the minimum number of coins for change.
>
> Given any number between 1 and 99, determine how to give change with
> the minimum number of coins. You can assume that the coins are 1c, 2c,
> 5c, 10c, 20c and 50c.
>
> Various solutions here in Scala, java, C#, Groovy...
> http://java.dzone.com/articles/thursday-code-puzzler-change
>
> ...and the xtalk implementation would be...
>
> --
> -Mark Wieder
> mwieder at ahsoftware.net
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
Dr Terry Judd
Senior Lecturer in Medical Education
Medical Eduction Unit
Faculty of Medicine, Dentistry & Health Sciences
The University of Melbourne
More information about the use-livecode
mailing list