END
;
-our (@kinds) = qw(swill grog fine shot);
+our (@kinds) = qw(Swill Grog Fine Shot);
our (@proofs) = qw(40 60 100);
sub parse_info ($$$\@$) {
@$storeary = @v;
}
-our (@haves,@want,@price);
+our (@have,@want,@price);
sub parse_args () {
@ARGV or badusage("need some information to go on");
while (@ARGV) {
$_ = shift @ARGV;
if (m/^have$/) {
- parse_info(1,0,1, @{ $haves[@haves] }, 'BUG');
+ parse_info(1,0,1, @{ $have[@have] }, 'have');
} elsif (m/^want$/) {
parse_info(1,0,0, @want, 'want');
} elsif (m/^price$/) {
sub badusage ($) {
my ($m) = @_;
- print STDERR "bad usage: $m\n\n$usage\n";
+ print STDERR "\nbad usage: $m\n\n$usage\n";
exit 16;
}
our $ff = '%6.1f';
+sub valid ($) {
+ my ($x) = @_;
+ defined $x and $x>0 and $x<1e4;
+}
+
sub prvff ($$\@$) {
my ($what, $format, $ary, $unit) = @_;
- printf("%-40s", "$what:");
- for my $i (qw(0 1 2)) {
+ printf("%-25s", "$what:");
+ for my $i (qw(0 1 2 3)) {
my $x= $ary->[$i];
- my $y= $x>0 && $x<1e5 ? sprintf $format, $x : ' x';
- printf " %-10s", $y;
+ my $y= valid($x) ? sprintf $format, $x : ' ';
+ printf " %-9s", $y;
}
printf " %s\n", $unit;
}
our @norm_price;
-our $best;
+our ($best, $best_norm_price);
+
+sub print_inputs () {
+ printf("%25s",'');
+ map { printf " %5s ", $_ } @kinds;
+ print "\n\n";
+ pr('prices', @price, 'poe ea.') if valid(@price);
+ pr('target stocks', @want, 'units') if valid(@want);
+ my $i=0; for my $stocks (@have) {
+ pr('actual stocks'.(@have==1 ? '' : ' #'.++$i),
+ @$stocks, 'units');
+ }
+ print "\n";
+}
sub compute_cheapest_rum() {
return unless @price;
+ my (@perorder) = map { $_*10 } @price;
+ prf('equiv. ordering price', @perorder, 'poe/order');
+
$best= undef;
my $best_norm_price= 1e5;
for my $i (qw(0 1 2)) {
next unless $price[$i];
- $norm_price[$i] = $price[$i] * $proofs[$i] / $proofs[$i];
+ $norm_price[$i] = $price[$i] * 100 / $proofs[$i];
if ($norm_price[$i] <= $best_norm_price) {
$best= $i;
+ $best_norm_price= $norm_price[$i];
}
};
prf('normalised prices', @norm_price, 'poe/fine');
+
if (defined $best) {
- printf "best is %s\n\n", $kinds[$best];
- } else {
- die "no rum available ?\n";
+ printf "best is %-10s%*s^^\n",
+ $kinds[$best],
+ $best*10+10, '';
+ my (@bestperorder) = map {
+ $best_norm_price * $proofs[$_] / 100 * 10;
+ } qw(0 1 2);
+ #push @bestperorder, $perorder[3];
+ prf('best is equiv. ordering', @bestperorder, 'poe/order');
}
+ print "\n";
}
parse_args();
-use Data::Dumper;
-print Dumper({ Have => \@haves, Want => \@want, Price => \@price });
+print_inputs();
compute_cheapest_rum();
__DATA__
+# if (defined $price{Swill}) {
+# map { $price{$_}= undef if $price{$_} eq 'x' } @rums;
+# }
+# if (defined $have{Swill}) {
+# $have_proof= 0;
+# map { $have_proof += $have{$_} * $proof{$_} } @rums;
+# }
+
our ($best);
our $have_proof;
-sub print_inputs () {
- printf("%40s",'');
- map { printf " %5s ", $_ } @rums;
- print "\n\n";
- if (defined $price{Swill}) {
- map { $price{$_}= undef if $price{$_} eq 'x' } @rums;
- pr('prices', %price, 'poe ea.');
- }
- if (defined $have{Swill}) {
- $have_proof= 0;
- map { $have_proof += $have{$_} * $proof{$_} } @rums;
- pr('stock on board', %have, 'rum');
- }
-}
-
our ($need_proof, %need, %buy);
sub compute_restock_requirements () {