]> www.fi.muni.cz Git - aoc.git/blob - 2015/41.pl
Day 25: examining the input
[aoc.git] / 2015 / 41.pl
1 #!/usr/bin/perl -w
2
3 use v5.16;
4 use strict;
5
6 my %weapons = (
7 'Dagger' => [ qw(       8     4       0 ) ],
8 'Shortsword' => [ qw(  10     5       0 ) ],
9 'Warhammer' => [ qw(   25     6       0 ) ],
10 'Longsword' => [ qw(   40     7       0 ) ],
11 'Greataxe' => [ qw(    74     8       0 ) ],
12 );
13
14 my %armors = (
15 'NONE'    => [ qw(      0     0       0 ) ],
16 'Leather' => [ qw(     13     0       1 ) ],
17 'Chainmail' => [ qw(   31     0       2 ) ],
18 'Splintmail' => [ qw(  53     0       3 ) ],
19 'Bandedmail' => [ qw(  75     0       4 ) ],
20 'Platemail' => [ qw(  102     0       5 ) ],
21 );
22
23 my %rings = (
24 'NONE_1'    => [ qw(    0     0       0 ) ],
25 'NONE_2'    => [ qw(    0     0       0 ) ],
26 'Damage_+1' => [ qw(   25     1       0 ) ],
27 'Damage_+2' => [ qw(   50     2       0 ) ],
28 'Damage_+3' => [ qw(  100     3       0 ) ],
29 'Defense_+1' => [ qw(  20     0       1 ) ],
30 'Defense_+2' => [ qw(  40     0       2 ) ],
31 'Defense_+3' => [ qw(  80     0       3 ) ],
32 );
33
34 my $boss = [ qw(104 8 1) ];
35
36 my $minprice;
37 for my $w (keys %weapons) {
38         for my $a (keys %armors) {
39                 for my $r1 (keys %rings) {
40                         for my $r2 (keys %rings) {
41                                 next if $r1 eq $r2;
42                                 my $price = $weapons{$w}->[0]
43                                         + $armors{$a}->[0]
44                                         + $rings{$r1}->[0]
45                                         + $rings{$r2}->[0];
46                                 my $damage = $weapons{$w}->[1]
47                                         + $armors{$a}->[1]
48                                         + $rings{$r1}->[1]
49                                         + $rings{$r2}->[1];
50                                 my $armor = $weapons{$w}->[2]
51                                         + $armors{$a}->[2]
52                                         + $rings{$r1}->[2]
53                                         + $rings{$r2}->[2];
54                                 my $pl = $damage - $boss->[2];
55                                 my $bo = $boss->[1] - $armor;
56                                 my ($bosshp, $playerhp) = ($boss->[0], 100);
57                                 while (1) {
58                                         $bosshp -= $pl;
59                                         if ($bosshp <= 0) {
60                                                 $minprice = $price if !$minprice || $price < $minprice;
61                                                 say "$price $w $a $r1 $r2";
62                                                 last;
63                                         }
64                                         $playerhp -= $bo;
65                                         last if ($playerhp <= 0);
66                                 }
67                         }
68                 }
69         }
70 }
71
72 say $minprice;
73                         
74                 
75                 
76         
77