Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created December 30, 2013 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobyink/8176950 to your computer and use it in GitHub Desktop.
Save tobyink/8176950 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
print "Amount (in pounds)?\n";
chomp(my $amount = <>);
$amount = sprintf('%.1f', $amount * 100);
my %coinage = (
1 => 'pennies',
2 => 'tuppennies',
5 => 'five pence pieces',
10 => 'ten pence pieces',
20 => 'twenty pence pieces',
50 => 'fifty pence pieces',
100 => 'pound coins',
200 => 'two pound coins',
);
my $remainder = $amount;
for my $value (sort { $b <=> $a } keys %coinage) {
my $quantity = int($remainder / $value);
print "$quantity $coinage{$value}\n" if $quantity;
$remainder %= $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment