Skip to content

Instantly share code, notes, and snippets.

@olostan
Created March 29, 2011 09:20
Show Gist options
  • Save olostan/892072 to your computer and use it in GitHub Desktop.
Save olostan/892072 to your computer and use it in GitHub Desktop.
Solution for POS Terminal (anti-howto in perl)
use List::Util qw(sum);
use POSIX qw(floor);
# Pricelist
%P = ( "A" => [1.25, 3, 3], "B" => 4.25, "C" => [1,6,5], D=> 0.75 );
# Sale scanning
$_{$_}++ for split (//,qw(ABCDABA));
# Calculate total
print "Total = ".sum map {
!ref $P{$_} ? $_{$_} * $P{$_} : floor($_{$_} / $P{$_}->[1])*$P{$_}->[2]+($_{$_} % $P{$_}->[1])*$P{$_}->[0];
} keys(%_);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment