]> www.fi.muni.cz Git - aoc.git/commitdiff
Day 14: creative part 2
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Mon, 16 Dec 2024 08:51:23 +0000 (09:51 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Mon, 16 Dec 2024 08:51:23 +0000 (09:51 +0100)
2024/27.pl [new file with mode: 0755]
2024/28.pl [new file with mode: 0755]

diff --git a/2024/27.pl b/2024/27.pl
new file mode 100755 (executable)
index 0000000..bbd57df
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/perl -w
+
+use v5.40;
+use List::Util qw(product);
+
+# my ($w, $h) = (11, 7);
+my ($w, $h) = (101, 103);
+my $steps = 100;
+
+my %count;
+while (<>) {
+       my ($x, $y, $vx, $vy) = /-?\d+/g;
+       $x += $steps * $vx;
+       $y += $steps * $vy;
+       $x %= $w;
+       $y %= $h;
+       my $q;
+       $q .= 'L' if $x < ($w-1)/2;
+       $q .= 'R' if $x > ($w-1)/2;
+       $q .= 'U' if $y < ($h-1)/2;
+       $q .= 'D' if $y > ($h-1)/2;
+       $count{$q}++ if length $q == 2;
+}
+
+say product values %count;
diff --git a/2024/28.pl b/2024/28.pl
new file mode 100755 (executable)
index 0000000..131d47e
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/perl -w
+
+use v5.40;
+
+my ($w, $h) = (101, 103);
+
+my @r = map { chomp; [ /-?\d+/g ] } <>;
+
+my $i = 0;
+while (1) {
+       my %pos;
+       for my $r (@r) {
+               $r->[0] = ($r->[0] + $r->[2]) % $w;
+               $r->[1] = ($r->[1] + $r->[3]) % $h;
+               $pos{$r->[1]}{$r->[0]}++;
+       }
+
+       # Count the symmetrical symbols across Y axis
+       my $sym = 0;
+       for my $y (0 .. $h-1) {
+               for my $x (0 .. $w-1) {
+                       $sym++ if $pos{$y}{$x} && $pos{$y}{$w - 1 - $x};
+               }
+       }
+       say "step ", ++$i, " sym $sym";
+       next if $sym < 100;
+
+       for my $y (0 .. $h-1) {
+               for my $x (0 .. $w-1) {
+                       if ($pos{$y}{$w - 1 - $x}) {
+                               print $pos{$y}{$x} ? 'O' : '.';
+                       } else {
+                               print $pos{$y}{$x} ? '#' : '.';
+                       }
+               }
+               print "\n";
+       }
+       sleep 1;
+}
+