days 5-11
This commit is contained in:
parent
d3ae65f625
commit
1d2d5def97
18 changed files with 804 additions and 0 deletions
72
10/1.pl
Normal file
72
10/1.pl
Normal file
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use v5.10;
|
||||
use Data::Dumper;
|
||||
|
||||
chomp (my @data = <STDIN>);
|
||||
|
||||
my (@cx, @cy, @vx, @vy);
|
||||
|
||||
foreach my $line (@data) {
|
||||
# position=< 9, 1> velocity=< 0, 2>
|
||||
|
||||
my ($x, $y, $vx, $vy) =
|
||||
($line =~ m/position=<\s*(-?\d+),\s*(-?\d+)> velocity=<\s*(-?\d+),\s*(-?\d+)>/);
|
||||
say "$x,$y - $vx,$vy";
|
||||
push @cx, $x;
|
||||
push @cy, $y;
|
||||
push @vx, $vx;
|
||||
push @vy, $vy;
|
||||
}
|
||||
|
||||
my $count = 0;
|
||||
my $triggered = 0;
|
||||
while () {
|
||||
$count++;
|
||||
my %sumY;
|
||||
for (my $i = 0; $i <= $#cx; $i++) {
|
||||
$cx[$i] += $vx[$i];
|
||||
$cy[$i] += $vy[$i];
|
||||
$sumY{$cy[$i]}++;
|
||||
#say "$i $cx[$i],$cy[$i]";
|
||||
}
|
||||
my @most = sort { $sumY{$b} <=> $sumY{$a} } keys %sumY;
|
||||
|
||||
if ($sumY{$most[0]} > 14 || $triggered) {
|
||||
say "count: $count";
|
||||
$triggered = 1;
|
||||
sleep 1;
|
||||
my $minx = 999999999;
|
||||
my $miny = 999999999;
|
||||
my $maxx = 0;
|
||||
my $maxy = 0;
|
||||
for (my $i = 0; $i <= $#cx; $i++) {
|
||||
($minx = $cx[$i]) if ($cx[$i] < $minx);
|
||||
($miny = $cy[$i]) if ($cy[$i] < $miny);
|
||||
($maxx = $cx[$i]) if ($cx[$i] > $maxx);
|
||||
($maxy = $cy[$i]) if ($cy[$i] > $maxy);
|
||||
}
|
||||
my %render;
|
||||
for (my $i = 0; $i <= $#cx; $i++) {
|
||||
$cx[$i] -= $minx;
|
||||
$cy[$i] -= $miny;
|
||||
#say "$cx[$i], $cy[$i]";
|
||||
$render{"$cx[$i],$cy[$i]"}=1;
|
||||
|
||||
}
|
||||
for (my $y = 0; $y <= ($maxy-$miny); $y++) {
|
||||
for (my $x = 0; $x <= ($maxx-$minx); $x++) {
|
||||
if ($render{"$x,$y"}) {
|
||||
print "#";
|
||||
} else {
|
||||
print " ";
|
||||
}
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
31
10/sample.txt
Normal file
31
10/sample.txt
Normal file
|
@ -0,0 +1,31 @@
|
|||
position=< 9, 1> velocity=< 0, 2>
|
||||
position=< 7, 0> velocity=<-1, 0>
|
||||
position=< 3, -2> velocity=<-1, 1>
|
||||
position=< 6, 10> velocity=<-2, -1>
|
||||
position=< 2, -4> velocity=< 2, 2>
|
||||
position=<-6, 10> velocity=< 2, -2>
|
||||
position=< 1, 8> velocity=< 1, -1>
|
||||
position=< 1, 7> velocity=< 1, 0>
|
||||
position=<-3, 11> velocity=< 1, -2>
|
||||
position=< 7, 6> velocity=<-1, -1>
|
||||
position=<-2, 3> velocity=< 1, 0>
|
||||
position=<-4, 3> velocity=< 2, 0>
|
||||
position=<10, -3> velocity=<-1, 1>
|
||||
position=< 5, 11> velocity=< 1, -2>
|
||||
position=< 4, 7> velocity=< 0, -1>
|
||||
position=< 8, -2> velocity=< 0, 1>
|
||||
position=<15, 0> velocity=<-2, 0>
|
||||
position=< 1, 6> velocity=< 1, 0>
|
||||
position=< 8, 9> velocity=< 0, -1>
|
||||
position=< 3, 3> velocity=<-1, 1>
|
||||
position=< 0, 5> velocity=< 0, -1>
|
||||
position=<-2, 2> velocity=< 2, 0>
|
||||
position=< 5, -2> velocity=< 1, 2>
|
||||
position=< 1, 4> velocity=< 2, 1>
|
||||
position=<-2, 7> velocity=< 2, -2>
|
||||
position=< 3, 6> velocity=<-1, -1>
|
||||
position=< 5, 0> velocity=< 1, 0>
|
||||
position=<-6, 0> velocity=< 2, 0>
|
||||
position=< 5, 9> velocity=< 1, -2>
|
||||
position=<14, 7> velocity=<-2, 0>
|
||||
position=<-3, 6> velocity=< 2, -1>
|
Loading…
Add table
Add a link
Reference in a new issue