source code for "files/pe/pe_031.pl"
return to portfolio
- #!/usr/bin/perl
- use strict;
- use warnings;
- use POSIX qw/ceil floor/;
- # for debugging
- sub print_hash {
- my ($h, $width) = @_;
- $width = 10 if not defined $width;
- for my $key (sort { $a <=> $b } keys %$h) {
- print "$key ", '.' x ($width - length $key + 1), " $h->{$key}\n";
- }
- }
- # variables declared/initialized
- my @coins = (1, 2, 5, 10, 20, 50, 100, 200);
- my $table = {0=>1};
- # bleh
- for my $c (@coins) {
- $table->{$_} += $table->{$_ - $c} for $c..200;
- }
- print $table->{200};