]> www.fi.muni.cz Git - aoc2021.git/blob - 38.pl
Day 25: pretty straightforward
[aoc2021.git] / 38.pl
1 #!/usr/bin/perl -w
2
3 use v5.16;
4
5 $; = ',';
6
7 sub transform {
8         my ($coords, $trans) = @_;
9         my @res;
10         for (0 .. $#$coords) {
11                 $res[$_] = $coords->[$trans->[$_]];
12                 $res[$_] *= -1 if $trans->[$_+@$coords] < 0;
13         }
14         return @res;
15 }
16
17 my %aligned_scanners = ('scanner 0' => [ 0, 0, 0 ]);
18
19 # parsing the debugging output of the first part ...
20 while (<>) {
21         my ($s1, $s2, $rest) = /(.*) and (.*) aligned: (.*) beacons:/;
22         next if !$rest;
23
24         my @r = split /,/, $rest;
25         my @off = @r[0..2];
26         my @rot = @r[3..8];
27
28         # @off = transform(\@off, \@rot);
29         say "$s1 to $s2";
30         # $off[$_] += $aligned_scanners{$s1}->[$_] for 0..2;
31         say "$s2 at ", join(',', @off);
32         $aligned_scanners{$s2} = [ @off ];
33 }
34
35 my $max_dist = 0;
36 for my $s1 (keys %aligned_scanners) {
37 for my $s2 (keys %aligned_scanners) {
38         my $dist;
39         $dist += abs($aligned_scanners{$s1}->[$_] - $aligned_scanners{$s2}->[$_]) for 0 .. 2;
40         $max_dist = $dist if $dist > $max_dist;
41         say "$s1 to $s2 = $dist";
42 } }
43
44 say $max_dist;
45