<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Code Challenge: Change Dispenser</title>
	<atom:link href="http://blog.stevenlevithan.com/archives/change-dispenser/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.stevenlevithan.com/archives/change-dispenser</link>
	<description>A JavaScript and regular expression centric blog</description>
	<lastBuildDate>Fri, 12 Mar 2010 14:48:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: John Vivenzio</title>
		<link>http://blog.stevenlevithan.com/archives/change-dispenser/comment-page-1#comment-32071</link>
		<dc:creator>John Vivenzio</dc:creator>
		<pubDate>Sat, 02 May 2009 06:27:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=79#comment-32071</guid>
		<description>Obscure bug?

When testing just now I found if you enter makeChange(279.96 * 100) - it rounds to 27995.9999 when multiplied by 100 - very bizarre. ...using Firefox 3.5b4  - reminds me of the Pentium 59.999... days.</description>
		<content:encoded><![CDATA[<p>Obscure bug?</p>
<p>When testing just now I found if you enter makeChange(279.96 * 100) &#8211; it rounds to 27995.9999 when multiplied by 100 &#8211; very bizarre. &#8230;using Firefox 3.5b4  &#8211; reminds me of the Pentium 59.999&#8230; days.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Vivenzio</title>
		<link>http://blog.stevenlevithan.com/archives/change-dispenser/comment-page-1#comment-32070</link>
		<dc:creator>John Vivenzio</dc:creator>
		<pubDate>Sat, 02 May 2009 05:58:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=79#comment-32070</guid>
		<description>Last One... with inventory of bills and coins and shows remainder if can&#039;t make exact change.

var b = [
// checkInventory to null out what&#039;s not available (on hand is b[i][1])
	[10000, 0, &quot;Hundred&quot;],
	[ 5000, 1, &quot;Fifty&quot;, &quot;Fifties&quot;],
	[ 2000, 0, &quot;Twenty&quot;, &quot;Twenties&quot;],
	[ 1000, 0, &quot;Ten&quot;],
	[  500, 0, &quot;Five&quot;],
	[  200, 0, &quot;Two&quot;],
	[  100, 0, &quot;Dollar&quot;],
	[   25, 0, &quot;quarter&quot;],
	[   10, 0, &quot;dime&quot;],
	[    5, 0, &quot;nickel&quot;],
	[    1, 0, &quot;penny&quot;, &quot;pennies&quot;],
	[    0]
];


function makeChange(money) {
    if (b[i][1] &amp;&amp; (x = Math.floor(money / b[i][0])))
        output.push(x + &quot; &quot; + (x &lt;= 1 ? b[i][2] : !b[i][3] ? b[i][2] + &quot;s&quot; : b[i][3]));
    return isNaN(b[i + 1]) ? makeChange(b[i][1] ? money % b[i++][0] : (i++, money)) : 
        output.push(&quot;Remainder: $&quot; + money / 100), output;
}

makeChange(123279.96 * 100).join(&quot;\n&quot;);</description>
		<content:encoded><![CDATA[<p>Last One&#8230; with inventory of bills and coins and shows remainder if can&#8217;t make exact change.</p>
<p>var b = [<br />
// checkInventory to null out what's not available (on hand is b[i][1])<br />
	[10000, 0, "Hundred"],<br />
	[ 5000, 1, "Fifty", "Fifties"],<br />
	[ 2000, 0, "Twenty", "Twenties"],<br />
	[ 1000, 0, "Ten"],<br />
	[  500, 0, "Five"],<br />
	[  200, 0, "Two"],<br />
	[  100, 0, "Dollar"],<br />
	[   25, 0, "quarter"],<br />
	[   10, 0, "dime"],<br />
	[    5, 0, "nickel"],<br />
	[    1, 0, "penny", "pennies"],<br />
	[    0]<br />
];</p>
<p>function makeChange(money) {<br />
    if (b[i][1] &amp;&amp; (x = Math.floor(money / b[i][0])))<br />
        output.push(x + &#8221; &#8221; + (x &lt;= 1 ? b[i][2] : !b[i][3] ? b[i][2] + &#8220;s&#8221; : b[i][3]));<br />
    return isNaN(b[i + 1]) ? makeChange(b[i][1] ? money % b[i++][0] : (i++, money)) :<br />
        output.push(&#8220;Remainder: $&#8221; + money / 100), output;<br />
}</p>
<p>makeChange(123279.96 * 100).join(&#8220;\n&#8221;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Vivenzio</title>
		<link>http://blog.stevenlevithan.com/archives/change-dispenser/comment-page-1#comment-32056</link>
		<dc:creator>John Vivenzio</dc:creator>
		<pubDate>Sat, 02 May 2009 04:04:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=79#comment-32056</guid>
		<description>Looking at the length of the other solutions around on here and the web (didn&#039;t see them before and never realized this is a famous problem) I think that code I just posted is

(c) 2009, John Vivenzio, All Rights Reserved

LOL

Great blog by the way!</description>
		<content:encoded><![CDATA[<p>Looking at the length of the other solutions around on here and the web (didn&#8217;t see them before and never realized this is a famous problem) I think that code I just posted is</p>
<p>(c) 2009, John Vivenzio, All Rights Reserved</p>
<p>LOL</p>
<p>Great blog by the way!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Vivenzio</title>
		<link>http://blog.stevenlevithan.com/archives/change-dispenser/comment-page-1#comment-32055</link>
		<dc:creator>John Vivenzio</dc:creator>
		<pubDate>Sat, 02 May 2009 03:52:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=79#comment-32055</guid>
		<description>Didn&#039;t think about that but just saw the ATM problem - that can be solved by running a checkInventory(array) on the array which nulls out or flags any change not available (in the above recursive) so the algorithm is easily adaptable.

-John</description>
		<content:encoded><![CDATA[<p>Didn&#8217;t think about that but just saw the ATM problem &#8211; that can be solved by running a checkInventory(array) on the array which nulls out or flags any change not available (in the above recursive) so the algorithm is easily adaptable.</p>
<p>-John</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Vivenzio</title>
		<link>http://blog.stevenlevithan.com/archives/change-dispenser/comment-page-1#comment-32054</link>
		<dc:creator>John Vivenzio</dc:creator>
		<pubDate>Sat, 02 May 2009 03:43:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=79#comment-32054</guid>
		<description>Here&#039;s a quick 2 line recursive I threw together... in the name of silly frugality - I just put the names that won&#039;t take an &#039;s&#039; in the [2] part of the array. : )

var n = [   
    [10000, &quot;Hundred&quot;],
    [ 5000, &quot;Fifty&quot;, &quot;Fifties&quot;],
    [ 2000, &quot;Twenty&quot;, &quot;Twenties&quot;],
    [ 1000, &quot;Ten&quot;],
    [  500, &quot;Five&quot;],
    [  200, &quot;Two&quot;],
    [  100, &quot;Dollar&quot;],
    [   25, &quot;quarter&quot;],
    [   10, &quot;dime&quot;],
    [    5, &quot;nickel&quot;],
    [    1, &quot;penny&quot;, &quot;pennies&quot;],
    [    0]
];

var output = [];
var i = 0, x = 0;

function makeChange(money) {
    if (x = Math.floor(money / n[i][0])) 
        output.push(x + &quot; &quot; + (x &lt;= 1 ? n[i][1] : !n[i][2] ? n[i][1] + &quot;s&quot; : n[i][2]));
    return isNaN(n[i + 1]) ? makeChange(money % n[i++][0]) : output;
}

makeChange(123279.96 * 100).join(&quot;\n&quot;);</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a quick 2 line recursive I threw together&#8230; in the name of silly frugality &#8211; I just put the names that won&#8217;t take an &#8217;s&#8217; in the [2] part of the array. : )</p>
<p>var n = [<br />
    [10000, "Hundred"],<br />
    [ 5000, "Fifty", "Fifties"],<br />
    [ 2000, "Twenty", "Twenties"],<br />
    [ 1000, "Ten"],<br />
    [  500, "Five"],<br />
    [  200, "Two"],<br />
    [  100, "Dollar"],<br />
    [   25, "quarter"],<br />
    [   10, "dime"],<br />
    [    5, "nickel"],<br />
    [    1, "penny", "pennies"],<br />
    [    0]<br />
];</p>
<p>var output = [];<br />
var i = 0, x = 0;</p>
<p>function makeChange(money) {<br />
    if (x = Math.floor(money / n[i][0]))<br />
        output.push(x + &#8221; &#8221; + (x &lt;= 1 ? n[i][1] : !n[i][2] ? n[i][1] + &#8220;s&#8221; : n[i][2]));<br />
    return isNaN(n[i + 1]) ? makeChange(money % n[i++][0]) : output;<br />
}</p>
<p>makeChange(123279.96 * 100).join(&#8220;\n&#8221;);</p>
]]></content:encoded>
	</item>
</channel>
</rss>
