day14
This commit is contained in:
parent
fdcd179eb0
commit
25281404f1
21
2015/13/1.pl
Normal file
21
2015/13/1.pl
Normal file
@ -0,0 +1,21 @@
|
||||
use 5.20.0;
|
||||
my %happiness;
|
||||
|
||||
while(<>) {
|
||||
/(?<from>\S+).*(?<gain>gain|lose) (?<happiness>\d+).*?(?<to>\S+)\.$/;
|
||||
$happiness{$+{from}}{$+{to}} = $+{happiness} * ( $+{gain} eq 'gain' ? 1 : -1 );
|
||||
}
|
||||
|
||||
use Algorithm::Combinatorics qw/ circular_permutations /;
|
||||
use List::AllUtils qw/ max sum /;
|
||||
|
||||
say max map { happiness_for($_) } circular_permutations([ keys %happiness ]);
|
||||
|
||||
sub happiness_for {
|
||||
my @group = @{ $_[0] };
|
||||
|
||||
sum map {
|
||||
my $who = $group[$_];
|
||||
map { $happiness{$who}{$group[ $_ ]} } map { $_ % @group } $_+1, $_ + @group - 1;
|
||||
} 0..$#group;
|
||||
}
|
23
2015/13/2.pl
Normal file
23
2015/13/2.pl
Normal file
@ -0,0 +1,23 @@
|
||||
use 5.20.0;
|
||||
my %happiness;
|
||||
|
||||
while(<>) {
|
||||
/(?<from>\S+).*(?<gain>gain|lose) (?<happiness>\d+).*?(?<to>\S+)\.$/;
|
||||
$happiness{$+{from}}{$+{to}} = $+{happiness} * ( $+{gain} eq 'gain' ? 1 : -1 );
|
||||
}
|
||||
|
||||
$happiness{yanick}{''} = 0;
|
||||
|
||||
use Algorithm::Combinatorics qw/ circular_permutations /;
|
||||
use List::AllUtils qw/ max sum /;
|
||||
|
||||
say max map { happiness_for($_) } circular_permutations([ keys %happiness ]);
|
||||
|
||||
sub happiness_for {
|
||||
my @group = @{ $_[0] };
|
||||
|
||||
sum map {
|
||||
my $who = $group[$_];
|
||||
map { $happiness{$who}{$group[ $_ ]} } map { $_ % @group } $_+1, $_ + @group - 1;
|
||||
} 0..$#group;
|
||||
}
|
56
2015/13/input.txt
Normal file
56
2015/13/input.txt
Normal file
@ -0,0 +1,56 @@
|
||||
Alice would gain 54 happiness units by sitting next to Bob.
|
||||
Alice would lose 81 happiness units by sitting next to Carol.
|
||||
Alice would lose 42 happiness units by sitting next to David.
|
||||
Alice would gain 89 happiness units by sitting next to Eric.
|
||||
Alice would lose 89 happiness units by sitting next to Frank.
|
||||
Alice would gain 97 happiness units by sitting next to George.
|
||||
Alice would lose 94 happiness units by sitting next to Mallory.
|
||||
Bob would gain 3 happiness units by sitting next to Alice.
|
||||
Bob would lose 70 happiness units by sitting next to Carol.
|
||||
Bob would lose 31 happiness units by sitting next to David.
|
||||
Bob would gain 72 happiness units by sitting next to Eric.
|
||||
Bob would lose 25 happiness units by sitting next to Frank.
|
||||
Bob would lose 95 happiness units by sitting next to George.
|
||||
Bob would gain 11 happiness units by sitting next to Mallory.
|
||||
Carol would lose 83 happiness units by sitting next to Alice.
|
||||
Carol would gain 8 happiness units by sitting next to Bob.
|
||||
Carol would gain 35 happiness units by sitting next to David.
|
||||
Carol would gain 10 happiness units by sitting next to Eric.
|
||||
Carol would gain 61 happiness units by sitting next to Frank.
|
||||
Carol would gain 10 happiness units by sitting next to George.
|
||||
Carol would gain 29 happiness units by sitting next to Mallory.
|
||||
David would gain 67 happiness units by sitting next to Alice.
|
||||
David would gain 25 happiness units by sitting next to Bob.
|
||||
David would gain 48 happiness units by sitting next to Carol.
|
||||
David would lose 65 happiness units by sitting next to Eric.
|
||||
David would gain 8 happiness units by sitting next to Frank.
|
||||
David would gain 84 happiness units by sitting next to George.
|
||||
David would gain 9 happiness units by sitting next to Mallory.
|
||||
Eric would lose 51 happiness units by sitting next to Alice.
|
||||
Eric would lose 39 happiness units by sitting next to Bob.
|
||||
Eric would gain 84 happiness units by sitting next to Carol.
|
||||
Eric would lose 98 happiness units by sitting next to David.
|
||||
Eric would lose 20 happiness units by sitting next to Frank.
|
||||
Eric would lose 6 happiness units by sitting next to George.
|
||||
Eric would gain 60 happiness units by sitting next to Mallory.
|
||||
Frank would gain 51 happiness units by sitting next to Alice.
|
||||
Frank would gain 79 happiness units by sitting next to Bob.
|
||||
Frank would gain 88 happiness units by sitting next to Carol.
|
||||
Frank would gain 33 happiness units by sitting next to David.
|
||||
Frank would gain 43 happiness units by sitting next to Eric.
|
||||
Frank would gain 77 happiness units by sitting next to George.
|
||||
Frank would lose 3 happiness units by sitting next to Mallory.
|
||||
George would lose 14 happiness units by sitting next to Alice.
|
||||
George would lose 12 happiness units by sitting next to Bob.
|
||||
George would lose 52 happiness units by sitting next to Carol.
|
||||
George would gain 14 happiness units by sitting next to David.
|
||||
George would lose 62 happiness units by sitting next to Eric.
|
||||
George would lose 18 happiness units by sitting next to Frank.
|
||||
George would lose 17 happiness units by sitting next to Mallory.
|
||||
Mallory would lose 36 happiness units by sitting next to Alice.
|
||||
Mallory would gain 76 happiness units by sitting next to Bob.
|
||||
Mallory would lose 34 happiness units by sitting next to Carol.
|
||||
Mallory would gain 37 happiness units by sitting next to David.
|
||||
Mallory would gain 40 happiness units by sitting next to Eric.
|
||||
Mallory would gain 18 happiness units by sitting next to Frank.
|
||||
Mallory would gain 7 happiness units by sitting next to George.
|
23
2015/14/1.pl
Normal file
23
2015/14/1.pl
Normal file
@ -0,0 +1,23 @@
|
||||
use 5.20.0;
|
||||
use List::AllUtils qw/ max/;
|
||||
use experimental qw/ postderef /;
|
||||
use List::UtilsBy qw/ max_by /;
|
||||
|
||||
my %reindeer =
|
||||
map { $_->[0] => [ ($_->[1]) x $_->[2], ( 0 ) x $_->[3] ] }
|
||||
map { [ /(\S+).*?(\d+).*?(\d+).*?(\d+)/ ] } <>;
|
||||
|
||||
use DDP;
|
||||
p %reindeer;
|
||||
|
||||
my %score;
|
||||
|
||||
for ( 0..2502 ) {
|
||||
while( my( $r, $s ) = each %reindeer ) {
|
||||
$score{$r} += $reindeer{$r}[ $_ % $reindeer{$r}->@* ]
|
||||
}
|
||||
}
|
||||
|
||||
say max values %score;
|
||||
|
||||
|
26
2015/14/2.pl
Normal file
26
2015/14/2.pl
Normal file
@ -0,0 +1,26 @@
|
||||
use 5.20.0;
|
||||
use List::AllUtils qw/ max/;
|
||||
use experimental qw/ postderef /;
|
||||
use List::UtilsBy qw/ max_by /;
|
||||
|
||||
my %reindeer =
|
||||
map { $_->[0] => [ ($_->[1]) x $_->[2], ( 0 ) x $_->[3] ] }
|
||||
map { [ /(\S+).*?(\d+).*?(\d+).*?(\d+)/ ] } <>;
|
||||
|
||||
use DDP;
|
||||
p %reindeer;
|
||||
|
||||
my %dist;
|
||||
my %score;
|
||||
|
||||
for ( 0..2502 ) {
|
||||
while( my( $r, $s ) = each %reindeer ) {
|
||||
$dist{$r} += $reindeer{$r}[ $_ % $reindeer{$r}->@* ]
|
||||
}
|
||||
my $max = max values %dist;
|
||||
$score{$_}++ for grep { $dist{$_} == $max } keys %dist;
|
||||
}
|
||||
|
||||
say max values %score;
|
||||
|
||||
|
9
2015/14/input.txt
Normal file
9
2015/14/input.txt
Normal file
@ -0,0 +1,9 @@
|
||||
Dancer can fly 27 km/s for 5 seconds, but then must rest for 132 seconds.
|
||||
Cupid can fly 22 km/s for 2 seconds, but then must rest for 41 seconds.
|
||||
Rudolph can fly 11 km/s for 5 seconds, but then must rest for 48 seconds.
|
||||
Donner can fly 28 km/s for 5 seconds, but then must rest for 134 seconds.
|
||||
Dasher can fly 4 km/s for 16 seconds, but then must rest for 55 seconds.
|
||||
Blitzen can fly 14 km/s for 3 seconds, but then must rest for 38 seconds.
|
||||
Prancer can fly 3 km/s for 21 seconds, but then must rest for 40 seconds.
|
||||
Comet can fly 18 km/s for 6 seconds, but then must rest for 103 seconds.
|
||||
Vixen can fly 18 km/s for 5 seconds, but then must rest for 84 seconds.
|
Loading…
Reference in New Issue
Block a user