#!/usr/bin/perl use v5.35.0; my @robots; while (<>) { if (/p=(-?\d+),(-?\d+) v=(-?\d+),(-?\d+)/) { push @robots, [$1, $2, $3, $4]; } } my $width = 101; my $height = 103; for my $steps (0 .. $width * $height) { my $map = ('.' x $width . "\n") x $height; for my $robot (@robots) { substr($map, $$robot[0] + $$robot[1] * ($width + 1), 1) = '@'; $$robot[0] += $$robot[2], $$robot[0] %= $width; $$robot[1] += $$robot[3], $$robot[1] %= $height; } if ($map =~ /@@@@@@@@@@/) { say $steps; print $map; } }