in reply to 1,000 bucks

How about this?
my $amount = shift; # disperse amount die "must be integer" if $amount != int($amount); die "too big" if $amount > 1000; die "too small" if $amount < 1; for (my $en = 1; $amount; $en <<= 1) { next unless $amount & $en; print "Giving you envelope with $en\n"; $amount &= ~ $en; }

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: 1,000 bucks
by cforde (Monk) on May 18, 2001 at 01:05 UTC
    Randal, that implies you have envelopes with 1, 2, 4, 8, 16, 32, 64, 128, 256 and 512 dollars. This totals more than 1000. oops. :-)

    Have fun,
    Carl Forde

      yeah, so you just chuck what's left into the 10th envelope - 489 i think (can't find my calculator)