|Problems? Is your data what you think it is?|
puzzle: how many ways to make $100by davidj (Priest)
|on Apr 28, 2006 at 23:26 UTC||Need Help??|
davidj has asked for the
wisdom of the Perl Monks concerning the following question:
My Fellow Monks,
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:
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.
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.
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.
Here's what I'm currently thinking:
step 1: get all combinations where each value in the combination is the same:
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:
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.
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.
As always, your input and teaching are most welcome.