leftovers
This commit is contained in:
parent
468f5a3a85
commit
fa9ba00a6b
1285
2018/03/input.txt
Normal file
1285
2018/03/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
15
2018/03/sol1.pl
Normal file
15
2018/03/sol1.pl
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
use 5.20.0;
|
||||||
|
|
||||||
|
my @clothe;
|
||||||
|
|
||||||
|
while( <> ) {
|
||||||
|
/(?<x>\d+),(?<y>\d+): (?<w>\d+)x(?<h>\d+)/ or die;
|
||||||
|
|
||||||
|
for my $x ( $+{x}...$+{x}+$+{w}-1 ) {
|
||||||
|
for my $y ( $+{y}...$+{y}+$+{h}-1 ) {
|
||||||
|
$clothe[$x][$y]++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
say scalar grep { $_ > 1 } map { $_ ? @$_ : () } @clothe;
|
31
2018/03/sol2.pl
Normal file
31
2018/03/sol2.pl
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
use 5.20.0;
|
||||||
|
|
||||||
|
my @lines =
|
||||||
|
map {
|
||||||
|
/(?<id>\d+).*?(?<x>\d+),(?<y>\d+): (?<w>\d+)x(?<h>\d+)/ or die;
|
||||||
|
+{ %+ }
|
||||||
|
}
|
||||||
|
<>;
|
||||||
|
|
||||||
|
my @clothe;
|
||||||
|
|
||||||
|
for ( @lines ) {
|
||||||
|
|
||||||
|
for my $x ( $_->{x}...$_->{x}+$_->{w}-1 ) {
|
||||||
|
for my $y ( $_->{y}...$_->{y}+$_->{h}-1 ) {
|
||||||
|
$clothe[$x][$y]++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
say scalar grep { $_ > 1 } map { $_ ? @$_ : () } @clothe;
|
||||||
|
|
||||||
|
|
||||||
|
LINE: for ( @lines ) {
|
||||||
|
for my $x ( $_->{x}...$_->{x}+$_->{w}-1 ) {
|
||||||
|
for my $y ( $_->{y}...$_->{y}+$_->{h}-1 ) {
|
||||||
|
next LINE if $clothe[$x][$y] > 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
say $_->{id};
|
||||||
|
}
|
3
2018/03/test.txt
Normal file
3
2018/03/test.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#1 @ 1,3: 4x4
|
||||||
|
#2 @ 3,1: 4x4
|
||||||
|
#3 @ 5,5: 2x2
|
101
2018/07/input.txt
Normal file
101
2018/07/input.txt
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
Step E must be finished before step H can begin.
|
||||||
|
Step Y must be finished before step T can begin.
|
||||||
|
Step F must be finished before step S can begin.
|
||||||
|
Step U must be finished before step K can begin.
|
||||||
|
Step X must be finished before step Z can begin.
|
||||||
|
Step Q must be finished before step W can begin.
|
||||||
|
Step W must be finished before step O can begin.
|
||||||
|
Step G must be finished before step A can begin.
|
||||||
|
Step N must be finished before step H can begin.
|
||||||
|
Step S must be finished before step H can begin.
|
||||||
|
Step K must be finished before step C can begin.
|
||||||
|
Step J must be finished before step H can begin.
|
||||||
|
Step T must be finished before step B can begin.
|
||||||
|
Step C must be finished before step P can begin.
|
||||||
|
Step L must be finished before step V can begin.
|
||||||
|
Step Z must be finished before step A can begin.
|
||||||
|
Step M must be finished before step A can begin.
|
||||||
|
Step A must be finished before step P can begin.
|
||||||
|
Step V must be finished before step O can begin.
|
||||||
|
Step I must be finished before step O can begin.
|
||||||
|
Step P must be finished before step H can begin.
|
||||||
|
Step O must be finished before step D can begin.
|
||||||
|
Step R must be finished before step B can begin.
|
||||||
|
Step D must be finished before step B can begin.
|
||||||
|
Step B must be finished before step H can begin.
|
||||||
|
Step J must be finished before step L can begin.
|
||||||
|
Step T must be finished before step V can begin.
|
||||||
|
Step Z must be finished before step M can begin.
|
||||||
|
Step G must be finished before step B can begin.
|
||||||
|
Step K must be finished before step L can begin.
|
||||||
|
Step Z must be finished before step H can begin.
|
||||||
|
Step L must be finished before step M can begin.
|
||||||
|
Step X must be finished before step A can begin.
|
||||||
|
Step N must be finished before step M can begin.
|
||||||
|
Step G must be finished before step M can begin.
|
||||||
|
Step A must be finished before step V can begin.
|
||||||
|
Step G must be finished before step S can begin.
|
||||||
|
Step G must be finished before step J can begin.
|
||||||
|
Step L must be finished before step A can begin.
|
||||||
|
Step A must be finished before step H can begin.
|
||||||
|
Step T must be finished before step M can begin.
|
||||||
|
Step X must be finished before step N can begin.
|
||||||
|
Step P must be finished before step O can begin.
|
||||||
|
Step Y must be finished before step F can begin.
|
||||||
|
Step U must be finished before step G can begin.
|
||||||
|
Step G must be finished before step O can begin.
|
||||||
|
Step P must be finished before step D can begin.
|
||||||
|
Step G must be finished before step L can begin.
|
||||||
|
Step Z must be finished before step P can begin.
|
||||||
|
Step C must be finished before step L can begin.
|
||||||
|
Step E must be finished before step B can begin.
|
||||||
|
Step T must be finished before step Z can begin.
|
||||||
|
Step D must be finished before step H can begin.
|
||||||
|
Step U must be finished before step N can begin.
|
||||||
|
Step E must be finished before step V can begin.
|
||||||
|
Step L must be finished before step D can begin.
|
||||||
|
Step K must be finished before step Z can begin.
|
||||||
|
Step O must be finished before step R can begin.
|
||||||
|
Step V must be finished before step R can begin.
|
||||||
|
Step L must be finished before step O can begin.
|
||||||
|
Step T must be finished before step H can begin.
|
||||||
|
Step E must be finished before step Q can begin.
|
||||||
|
Step S must be finished before step T can begin.
|
||||||
|
Step U must be finished before step M can begin.
|
||||||
|
Step Q must be finished before step V can begin.
|
||||||
|
Step I must be finished before step B can begin.
|
||||||
|
Step L must be finished before step Z can begin.
|
||||||
|
Step Y must be finished before step B can begin.
|
||||||
|
Step J must be finished before step C can begin.
|
||||||
|
Step F must be finished before step Q can begin.
|
||||||
|
Step J must be finished before step D can begin.
|
||||||
|
Step Q must be finished before step L can begin.
|
||||||
|
Step I must be finished before step D can begin.
|
||||||
|
Step N must be finished before step V can begin.
|
||||||
|
Step U must be finished before step H can begin.
|
||||||
|
Step J must be finished before step R can begin.
|
||||||
|
Step K must be finished before step V can begin.
|
||||||
|
Step G must be finished before step P can begin.
|
||||||
|
Step Y must be finished before step X can begin.
|
||||||
|
Step L must be finished before step H can begin.
|
||||||
|
Step R must be finished before step D can begin.
|
||||||
|
Step S must be finished before step C can begin.
|
||||||
|
Step Q must be finished before step A can begin.
|
||||||
|
Step U must be finished before step X can begin.
|
||||||
|
Step V must be finished before step B can begin.
|
||||||
|
Step U must be finished before step Z can begin.
|
||||||
|
Step F must be finished before step P can begin.
|
||||||
|
Step G must be finished before step D can begin.
|
||||||
|
Step O must be finished before step H can begin.
|
||||||
|
Step C must be finished before step D can begin.
|
||||||
|
Step L must be finished before step P can begin.
|
||||||
|
Step N must be finished before step I can begin.
|
||||||
|
Step Q must be finished before step O can begin.
|
||||||
|
Step Q must be finished before step D can begin.
|
||||||
|
Step Z must be finished before step D can begin.
|
||||||
|
Step Y must be finished before step N can begin.
|
||||||
|
Step M must be finished before step O can begin.
|
||||||
|
Step W must be finished before step R can begin.
|
||||||
|
Step S must be finished before step D can begin.
|
||||||
|
Step O must be finished before step B can begin.
|
||||||
|
Step I must be finished before step P can begin.
|
22
2018/07/sol1.pl
Normal file
22
2018/07/sol1.pl
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
use 5.20.0;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use experimental qw/
|
||||||
|
signatures
|
||||||
|
postderef
|
||||||
|
/;
|
||||||
|
|
||||||
|
use Graph::Directed;
|
||||||
|
|
||||||
|
my $g = Graph::Directed->new;
|
||||||
|
|
||||||
|
while(<>) {
|
||||||
|
/Step (.).*before step (.)/;
|
||||||
|
$g->add_edge( $1 => $2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
while( my @x = sort $g->predecessorless_vertices ) {
|
||||||
|
print $x[0];
|
||||||
|
$g->delete_vertex($x[0]);
|
||||||
|
}
|
||||||
|
|
63
2018/07/sol2.pl
Normal file
63
2018/07/sol2.pl
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
use 5.20.0;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use experimental qw/
|
||||||
|
signatures
|
||||||
|
postderef
|
||||||
|
/;
|
||||||
|
|
||||||
|
use List::UtilsBy qw/ nsort_by /;
|
||||||
|
use List::AllUtils qw/ min /;
|
||||||
|
|
||||||
|
use Sim;
|
||||||
|
|
||||||
|
use Graph::Directed;
|
||||||
|
|
||||||
|
my $g = Graph::Directed->new;
|
||||||
|
|
||||||
|
while(<>) {
|
||||||
|
/Step (.).*before step (.)/;
|
||||||
|
$g->add_edge( $1 => $2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
my $workers = 5;
|
||||||
|
|
||||||
|
Sim->schedule(
|
||||||
|
0 => \&check_for_work,
|
||||||
|
);
|
||||||
|
|
||||||
|
my %available = map { $_ => 1 } $g->vertices;
|
||||||
|
|
||||||
|
Sim->run( fires => 100_000 );
|
||||||
|
|
||||||
|
sub time_for {
|
||||||
|
ord(shift) - ord('A') + 1 + 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub check_for_work {
|
||||||
|
say "time: ", Sim->now;
|
||||||
|
|
||||||
|
my @next = sort $g->predecessorless_vertices or return;
|
||||||
|
|
||||||
|
while( $workers ) {
|
||||||
|
my $next = shift @next or return;
|
||||||
|
|
||||||
|
$available{$next} or next;
|
||||||
|
|
||||||
|
delete $available{$next};
|
||||||
|
|
||||||
|
$workers--;
|
||||||
|
|
||||||
|
Sim->schedule(
|
||||||
|
Sim->now + time_for($next) => sub {
|
||||||
|
say "time done $next: ", Sim->now;
|
||||||
|
$g->delete_vertex($next);
|
||||||
|
$workers++;
|
||||||
|
Sim->schedule( Sim->now, \&check_for_work );
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
7
2018/07/test.txt
Normal file
7
2018/07/test.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Step C must be finished before step A can begin.
|
||||||
|
Step C must be finished before step F can begin.
|
||||||
|
Step A must be finished before step B can begin.
|
||||||
|
Step A must be finished before step D can begin.
|
||||||
|
Step B must be finished before step E can begin.
|
||||||
|
Step D must be finished before step E can begin.
|
||||||
|
Step F must be finished before step E can begin.
|
1
2018/09/input.txt
Normal file
1
2018/09/input.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
419 players; last marble is worth 72164 points
|
44
2018/09/sol1.pl
Normal file
44
2018/09/sol1.pl
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
use 5.20.0;
|
||||||
|
use warnings;
|
||||||
|
use experimental qw/
|
||||||
|
signatures
|
||||||
|
postderef
|
||||||
|
/;
|
||||||
|
|
||||||
|
my @marbles;
|
||||||
|
my $next_marble = 0;
|
||||||
|
my $index = 0;
|
||||||
|
|
||||||
|
my $nbr_elves = 419;
|
||||||
|
my $current_elf = 0;
|
||||||
|
my $last_marble = 72164 * 100;
|
||||||
|
|
||||||
|
my %score;
|
||||||
|
|
||||||
|
while() {
|
||||||
|
warn $next_marble if 0 == $next_marble % 10_000;
|
||||||
|
last if $next_marble > $last_marble;
|
||||||
|
if( $next_marble > 0 and 0 == $next_marble % 23 ) {
|
||||||
|
$index = ( $index - 7 + @marbles ) % @marbles;
|
||||||
|
my $score = $next_marble + splice @marbles, $index, 1;
|
||||||
|
$score{$current_elf} += $score;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$index = ( $index + 2 ) % ( @marbles || 1 );
|
||||||
|
splice @marbles, $index, 0, $next_marble;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# say join ' ', @marbles;
|
||||||
|
# my $x = <>;
|
||||||
|
|
||||||
|
$next_marble++;
|
||||||
|
$current_elf++;
|
||||||
|
$current_elf %= $nbr_elves;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
use List::UtilsBy qw/ max_by /;
|
||||||
|
use List::AllUtils qw/ pairs max /;
|
||||||
|
|
||||||
|
say max values %score;
|
Loading…
Reference in New Issue
Block a user