Matt Owen

source code for "files/pe/pe_031.pl"

return to portfolio
  1.  #!/usr/bin/perl
  2.  
  3.  use strict;
  4.  use warnings;
  5.  use POSIX qw/ceil floor/;
  6.  
  7.  # for debugging
  8.  sub print_hash {
  9.   my ($h, $width) = @_;
  10.   $width = 10 if not defined $width;
  11.   for my $key (sort { $a <=> $b } keys %$h) {
  12.   print "$key ", '.' x ($width - length $key + 1), " $h->{$key}\n";
  13.   }
  14.  }
  15.  
  16.  
  17.  # variables declared/initialized
  18.  my @coins = (1, 2, 5, 10, 20, 50, 100, 200);
  19.  my $table = {0=>1};
  20.  
  21.  
  22.  # bleh
  23.  for my $c (@coins) {
  24.   $table->{$_} += $table->{$_ - $c} for $c..200;
  25.  }
  26.  
  27.  print $table->{200};