]> www.fi.muni.cz Git - aoc.git/blobdiff - 2015/41.pl
Year 2015
[aoc.git] / 2015 / 41.pl
diff --git a/2015/41.pl b/2015/41.pl
new file mode 100755 (executable)
index 0000000..969500a
--- /dev/null
@@ -0,0 +1,77 @@
+#!/usr/bin/perl -w
+
+use v5.16;
+use strict;
+
+my %weapons = (
+'Dagger' => [ qw(       8     4       0 ) ],
+'Shortsword' => [ qw(  10     5       0 ) ],
+'Warhammer' => [ qw(   25     6       0 ) ],
+'Longsword' => [ qw(   40     7       0 ) ],
+'Greataxe' => [ qw(    74     8       0 ) ],
+);
+
+my %armors = (
+'NONE'    => [ qw(      0     0       0 ) ],
+'Leather' => [ qw(     13     0       1 ) ],
+'Chainmail' => [ qw(   31     0       2 ) ],
+'Splintmail' => [ qw(  53     0       3 ) ],
+'Bandedmail' => [ qw(  75     0       4 ) ],
+'Platemail' => [ qw(  102     0       5 ) ],
+);
+
+my %rings = (
+'NONE_1'    => [ qw(    0     0       0 ) ],
+'NONE_2'    => [ qw(    0     0       0 ) ],
+'Damage_+1' => [ qw(   25     1       0 ) ],
+'Damage_+2' => [ qw(   50     2       0 ) ],
+'Damage_+3' => [ qw(  100     3       0 ) ],
+'Defense_+1' => [ qw(  20     0       1 ) ],
+'Defense_+2' => [ qw(  40     0       2 ) ],
+'Defense_+3' => [ qw(  80     0       3 ) ],
+);
+
+my $boss = [ qw(104 8 1) ];
+
+my $minprice;
+for my $w (keys %weapons) {
+       for my $a (keys %armors) {
+               for my $r1 (keys %rings) {
+                       for my $r2 (keys %rings) {
+                               next if $r1 eq $r2;
+                               my $price = $weapons{$w}->[0]
+                                       + $armors{$a}->[0]
+                                       + $rings{$r1}->[0]
+                                       + $rings{$r2}->[0];
+                               my $damage = $weapons{$w}->[1]
+                                       + $armors{$a}->[1]
+                                       + $rings{$r1}->[1]
+                                       + $rings{$r2}->[1];
+                               my $armor = $weapons{$w}->[2]
+                                       + $armors{$a}->[2]
+                                       + $rings{$r1}->[2]
+                                       + $rings{$r2}->[2];
+                               my $pl = $damage - $boss->[2];
+                               my $bo = $boss->[1] - $armor;
+                               my ($bosshp, $playerhp) = ($boss->[0], 100);
+                               while (1) {
+                                       $bosshp -= $pl;
+                                       if ($bosshp <= 0) {
+                                               $minprice = $price if !$minprice || $price < $minprice;
+                                               say "$price $w $a $r1 $r2";
+                                               last;
+                                       }
+                                       $playerhp -= $bo;
+                                       last if ($playerhp <= 0);
+                               }
+                       }
+               }
+       }
+}
+
+say $minprice;
+                       
+               
+               
+       
+