X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=38.pl;fp=38.pl;h=b604ecc0e58af91a419fe4df02700c73a6e36b4a;hb=51f951351d95b416c9f27b4660d230e5b2cf8541;hp=0000000000000000000000000000000000000000;hpb=ab08f90e568538823f4c150df9b6641849b78123;p=aoc2021.git diff --git a/38.pl b/38.pl new file mode 100755 index 0000000..b604ecc --- /dev/null +++ b/38.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl -w + +use v5.16; + +$; = ','; + +sub transform { + my ($coords, $trans) = @_; + my @res; + for (0 .. $#$coords) { + $res[$_] = $coords->[$trans->[$_]]; + $res[$_] *= -1 if $trans->[$_+@$coords] < 0; + } + return @res; +} + +my %aligned_scanners = ('scanner 0' => [ 0, 0, 0 ]); + +# parsing the debugging output of the first part ... +while (<>) { + my ($s1, $s2, $rest) = /(.*) and (.*) aligned: (.*) beacons:/; + next if !$rest; + + my @r = split /,/, $rest; + my @off = @r[0..2]; + my @rot = @r[3..8]; + + # @off = transform(\@off, \@rot); + say "$s1 to $s2"; + # $off[$_] += $aligned_scanners{$s1}->[$_] for 0..2; + say "$s2 at ", join(',', @off); + $aligned_scanners{$s2} = [ @off ]; +} + +my $max_dist = 0; +for my $s1 (keys %aligned_scanners) { +for my $s2 (keys %aligned_scanners) { + my $dist; + $dist += abs($aligned_scanners{$s1}->[$_] - $aligned_scanners{$s2}->[$_]) for 0 .. 2; + $max_dist = $dist if $dist > $max_dist; + say "$s1 to $s2 = $dist"; +} } + +say $max_dist; +