perlquestion
davidj
My Fellow Monks, <BR><BR>
Every friday I volunteer my mornings in my daughter's classroom. (It's the most valuable 3 hours I spend each week). They are currently on a unit about money: monetary denominations (American), making change, etc. Today the teacher asked them "how many ways can you make $10?" It was an excellent opportunity for them to test their counting skills, especially involving objects that have weighted values. It took them awhile, but they came up with the correct answer:<BR>
<code>
(1 ten), (2 5's), (1 5 and 5 1's), and (10 1's)
</code>
That got me to thinking: How could one determine that for an arbitrary amount, say $100? This question has challenged me off and on for the better part of the afternoon.<BR><BR>
At first, I thought about using a weighted graph of some sort. That got me nowhere quickly. Not that I don't know what a weighted graph is, but my understanding of how to use graphs is very weak.<BR>
Next I thought about implementing some algorithm where I build down, incrementing to the next highest denomination (gowing down), or building up, incrementing to the next lowest denomination (going up). It seemed like a good idea, but I got stuck on how to implement it.<BR><BR>
Here's what I'm currently thinking:<BR>
step 1: get all combinations where each value in the combination is the same:<BR>
<code>
(1 100), (2 50's), (5 20's), (10 10's), (20 5'2), and (100 1's)
</code>
step 2: recursively drill down each one of them creating a new list consisting of the combinations that take the next fewest bills. For example:<BR>
<code>
[50, 50] -> [20,20,10, 50] -> [10,10, 20, 10, 50] (and so on)
</code>
My problem is, (as you can clearly see by my previous posts), I'm not a good algorithms guy. I'm working on it, but I have a long way to go. And regarding this particular little puzzle, I'm not sure how to implement my idea. Also, I imagine there are much better ways to go about it.<BR><BR>
The reason I'm seeking your assistance, other than for the learning, is that I think it would be pretty cool to write a little program that my daughter and her classmates can use to test differnt amounts and develop their math/counting/logic skills.<BR><BR>
As always, your input and teaching are most welcome.<BR>
davidj