Someone posted this challenge at work..
The country of Elbonia is standardizing its postal system to streamline its parcel service. All parcel boxes (many sizes available) now come with 10 preprinted rectangles on one side for stamps to be stuck into. Elbonia's stamp denominations are:
1c, 2c, 3c, 4c, 5c, 10c, 24c, 37c, 39c, 41c, 48c, 60c, 63c, 70c, 75c, 80c, 83c, 84c, 87c, $1, $3.85, $4.05, $4.60, $5, $14.40
Given an infinite supply of each denomination, what is the minimum postage amount that would REQUIRE 11 stamps and so not work with the streamlined service?
my$w={0=>1,1=>1,2=>2,3=>3,4=>4,5=>5,10=>
10,24=>24,37=>37,39=>39,41=>41,48=>48,60
=>60 ,63=>
63, 70=> 70,75
=>75 ,80=>80 ,83=>
83, 84=>84,87=>87, 100=>
100, 385=>385,405=>405 ,460=>
460 ,500=>500,1440=> 1440};
my@a =sort{$a<=>$b}keys %{$w};
for( 1..9){foreach my$c (keys
%{$w} ){foreach my $v(@a) {my $n
=$c+ $v;if(!exists$w-> {$n})
{$w ->{$n}=$w->{$c}. "+".$v
;}}} }my@r=sort{$a<=> $b}keys
%{$w };my$h=pop@r; for my$i
(0.. $h){if(exists $w->{$
i}){ print"$ i->".
$w-> {$i}."\n" ;}###
else{ print"!$i \n";}
}### # ########## #####
#### # ############ #####
#### # ############## #####
#### # ################ #####
#### ################### #####
#### ############## #####
#### ## ##
########################################
##### # ########### ############## #####
########################################
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.