--- /dev/null
+#!/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;
--- /dev/null
+#!/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;
+}
+