From: Jan "Yenya" Kasprzak Date: Mon, 16 Dec 2024 08:51:23 +0000 (+0100) Subject: Day 14: creative part 2 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=98db2efb7b3f969b1fdc083c7083b114f04af1cd;p=aoc.git Day 14: creative part 2 --- diff --git a/2024/27.pl b/2024/27.pl new file mode 100755 index 0000000..bbd57df --- /dev/null +++ b/2024/27.pl @@ -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 index 0000000..131d47e --- /dev/null +++ b/2024/28.pl @@ -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; +} +