Coding challenge

dunbarx at aol.com dunbarx at aol.com
Wed Jan 30 23:38:41 EST 2013


I think, as usual, Jacque's is the most original.


Craig


on makeChange pAmt
   repeat for each item i in "50,20,10,5,2,1"
     put i &"="& pAmt div i & cr after tList
     put pAmt mod i into pAmt
   end repeat
   filter tList without "*=0"
   put tList into fld "change"
end makeChange





-----Original Message-----
From: J. Landman Gay <jacque at hyperactivesw.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Sent: Wed, Jan 30, 2013 11:00 pm
Subject: Re: Coding challenge


On 1/30/13 9: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...
>
>

Didn't test all possible values, but so far this works:

on makeChange pAmt
   repeat for each item i in "50,20,10,5,2,1"
     put i &"="& pAmt div i & cr after tList
     put pAmt mod i into pAmt
   end repeat
   filter tList without "*=0"
   put tList into fld "change"
end makeChange

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
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

 



More information about the Use-livecode mailing list