Syntactic Confectionery Delight | |
PerlMonks |
1,000 bucksby idnopheq (Chaplain) |
on May 17, 2001 at 22:57 UTC ( [id://81336]=CUFP: print w/replies, xml ) | Need Help?? |
I found the following puzzle here
, very similar to one I did in high school Pascal class.
"A man told his son that he would give him $1000 if he could accomplish the following task. The father gave his son ten envelopes and a thousand dollars, all in one dollar bills. He told his son, "Place the money in the envelopes in such a manner that no matter what number of dollars I ask for, you can give me one or more of the envelopes, containing the exact amount I asked for without having to open any of the envelopes. If you can do this, you will keep the $1000." When the father asked for a sum of money, the son was able to give him envelopes containing the exact amount of money asked for. How did the son distribute the money among the ten envelopes?" I've also read it as a guy at an auction buying a car, etc. Anyway, our assignment for class went a few steps further. We had to initialy take in any amount of money, place the cash in as few envelopes as possible, and exit if the initial amount is less than the amount of money asked for in return. I no longer suffer myself to code in Pascal, and I thought this fun for Perl. Here's mine, dashed off while on a conference call today ... no doubt there are more efficient ways to accomplish this ... curious to see the mix of TIMTOWTDI. UPDATE: THX to gaudior for pointing out that CarTalk did this as one of their puzzles a ways back ... I could not remember what put the bug in my bonnet about this. Also, feel free to golf this ... those of you who haven't yet.
-- idnopheq Apply yourself to new problems without preparation, develop confidence in your ability to to meet situations as they arrise.
Back to
Cool Uses for Perl
|
|