--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my @dir = ([0, -1], [1, 0], [0, 1], [-1, 0]);
+my $d = 0;
+
+my ($x, $y) = (0, 0);
+
+$_ = <>;
+while (/([LR])(\d+)/g) {
+ if ($1 eq 'L') {
+ $d = $#dir if --$d < 0;
+ } else {
+ $d = 0 if ++$d > $#dir;
+ }
+ $x += $2 * $dir[$d]->[0];
+ $y += $2 * $dir[$d]->[1];
+}
+
+say abs($x)+abs($y);
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my @dir = ([0, -1], [1, 0], [0, 1], [-1, 0]);
+my $d = 0;
+
+my ($x, $y) = (0, 0);
+
+$_ = <>;
+my %seen;
+while (/([LR])(\d+)/g) {
+ if ($1 eq 'L') {
+ $d = $#dir if --$d < 0;
+ } else {
+ $d = 0 if ++$d > $#dir;
+ }
+ my $i = $2;
+ while ($i--) {
+ $x += $dir[$d]->[0];
+ $y += $dir[$d]->[1];
+ if ($seen{$x,$y}++) {
+ say abs($x)+abs($y);
+ exit 0;
+ }
+ }
+}
+
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+$; = ',';
+my %pos2num = (
+ "0,0" => 1,
+ "1,0" => 2,
+ "2,0" => 3,
+ "0,1" => 4,
+ "1,1" => 5,
+ "2,1" => 6,
+ "0,2" => 7,
+ "1,2" => 8,
+ "2,2" => 9,
+);
+my @pos = (1, 1);
+my $ret = '';
+while (<>) {
+ chomp;
+ for my $step (split //) {
+ $pos[0]-- if $pos[0] && $step eq 'L';
+ $pos[0]++ if $pos[0] < 2 && $step eq 'R';
+ $pos[1]-- if $pos[1] && $step eq 'U';
+ $pos[1]++ if $pos[1] < 2 && $step eq 'D';
+ }
+ $ret .= $pos2num{$pos[0],$pos[1]};
+}
+
+say $ret;
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+$; = ',';
+my %pos2num = (
+ "2,0" => 1,
+ "1,1" => 2,
+ "2,1" => 3,
+ "3,1" => 4,
+ "0,2" => 5,
+ "1,2" => 6,
+ "2,2" => 7,
+ "3,2" => 8,
+ "4,2" => 9,
+ "1,3" => 'A',
+ "2,3" => 'B',
+ "3,3" => 'C',
+ "2,4" => 'D',
+);
+my @pos = (0, 2);
+my $ret = '';
+while (<>) {
+ chomp;
+ for my $step (split //) {
+ $pos[0]-- if $pos2num{ ($pos[0]-1).",$pos[1]" } && $step eq 'L';
+ $pos[0]++ if $pos2num{ ($pos[0]+1).",$pos[1]" } && $step eq 'R';
+ $pos[1]-- if $pos2num{ "$pos[0],".($pos[1]-1) } && $step eq 'U';
+ $pos[1]++ if $pos2num{ "$pos[0],".($pos[1]+1) } && $step eq 'D';
+ }
+ $ret .= $pos2num{$pos[0],$pos[1]};
+}
+
+say $ret;
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my $valid;
+while (<>) {
+ chomp;
+ my (@d) = sort { $a <=> $b } /(\d+)/g;
+ $valid++ if $d[0]+$d[1] > $d[2];
+}
+
+say $valid;
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my $valid;
+my @d;
+while (<>) {
+ chomp;
+ push @d, [ /(\d+)/g ];
+ if (@d == 3) {
+ for my $c (0 .. 2) {
+ my @t = sort { $a <=> $b } ($d[0][$c], $d[1][$c], $d[2][$c]);
+ $valid++ if $t[0]+$t[1] > $t[2];
+ }
+ @d = ();
+ }
+}
+
+say $valid;
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my $sum;
+while (<>) {
+ chomp;
+ my ($code, $id, $csum) = /\A([a-z-]+)-(\d+)\[([a-z]{5})\]/;
+ my %hist;
+ $hist{$&}++ while ($code =~ /[a-z]/g);
+ my $c1;
+ for my $l (sort { $hist{$b} <=> $hist{$a} || $a cmp $b } keys %hist) {
+ $c1 .= $l;
+ last if length $c1 >= length $csum;
+ }
+ $sum += $id if $csum eq $c1;
+}
+say $sum;
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my $sum;
+while (<>) {
+ chomp;
+ my ($code, $id, $csum) = /\A([a-z-]+)-(\d+)\[([a-z]{5})\]/;
+ my $d;
+ $code =~ s/-/ /g;
+ for (split //, $code) {
+ if ($_ eq ' ') {
+ $d .= ' ';
+ next;
+ }
+ $d .= chr(ord('a') + ((ord($_)-ord('a')+$id) % 26));
+ }
+ say $id if $d =~ /pole/;
+}
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+use Digest::MD5 qw(md5_hex);
+
+my $id = 'ugkcyxxp';
+my $pass = '';
+my $i = 0;
+while (length($pass) < 8) {
+ my $h = md5_hex($id.$i);
+ if ($h =~ /\A00000/) {
+ $pass .= substr($h, 5, 1);
+ }
+ $i++;
+}
+
+say $pass;
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+use Digest::MD5 qw(md5_hex);
+
+my $id = 'ugkcyxxp';
+my $pass = ' ' x 8;
+my $i = 0;
+while ($pass =~ /\s/) {
+ my $h = md5_hex($id.$i);
+ if ($h =~ /\A00000/) {
+ my $pos = substr($h, 5, 1);
+ if ($pos =~ /[0-7]/ && substr($pass, $pos, 1) eq ' ') {
+ substr($pass, $pos, 1) = substr($h, 6, 1);
+ }
+ }
+ $i++;
+}
+
+say $pass;
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my %h;
+while (<>) {
+ chomp;
+ my $i = 0;
+ for my $l (split //) {
+ $h{$i++}{$l}++;
+ }
+}
+
+my $p;
+
+for my $i (0..7) {
+ my @a = sort { $h{$i}{$b} <=> $h{$i}{$a} } keys %{ $h{$i} };
+ $p .= $a[0];
+}
+
+say $p;
+
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my %h;
+while (<>) {
+ chomp;
+ my $i = 0;
+ for my $l (split //) {
+ $h{$i++}{$l}++;
+ }
+}
+
+my $p;
+
+for my $i (0..7) {
+ my @a = sort { $h{$i}{$b} <=> $h{$i}{$a} } keys %{ $h{$i} };
+ $p .= $a[-1];
+}
+
+say $p;
+
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my $count;
+
+while (<>) {
+ chomp;
+ next if /\[[^\]]*(\w)(?!\1)(\w)\2\1/;
+ next if !/(\w)(?!\1)(\w)\2\1/;
+ $count++;
+ say;
+}
+
+say $count;
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my $count;
+
+line:
+while (<>) {
+ chomp;
+ my $super = $_;
+ $super =~ s/\[.*?\]/---/g;
+ my $hyper = join('---', ($_ =~ /\[([^\]]*)\]/g));
+ while ($super =~ /(\w)(?!\1)(\w)\1/g) {
+ pos($super)-= 2;
+ my $s = "$2$1$2";
+ if ($hyper =~ /$s/) {
+ $count++;
+ next line;
+ }
+ }
+}
+
+say $count;
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my %screen;
+my ($w, $h) = (50, 6);
+$; = ',';
+
+while (<>) {
+ if (/rect (\d+)x(\d+)/) {
+ for my $x (0 .. $1-1) {
+ for my $y (0 .. $2-1) {
+ $screen{$x,$y} = 1;
+ } }
+ } elsif (/rotate row y=(\d+) by (\d+)/) {
+ my %ns = %screen;
+ for my $x (0 .. $w-1) {
+ my $sx = $x - $2;
+ $sx += $w if $sx < 0;
+ $ns{$x,$1} = $screen{$sx,$1};
+ }
+ %screen = %ns;
+ } elsif (/rotate column x=(\d+) by (\d+)/) {
+ my %ns = %screen;
+ for my $y (0 .. $h-1) {
+ my $sy = $y - $2;
+ $sy += $h if $sy < 0;
+ $ns{$1,$y} = $screen{$1,$sy};
+ }
+ %screen = %ns;
+ }
+}
+
+my $sum =()= grep { $screen{$_} } keys %screen;
+
+say $sum;
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my %screen;
+my ($w, $h) = (50, 6);
+$; = ',';
+
+while (<>) {
+ if (/rect (\d+)x(\d+)/) {
+ for my $x (0 .. $1-1) {
+ for my $y (0 .. $2-1) {
+ $screen{$x,$y} = 1;
+ } }
+ } elsif (/rotate row y=(\d+) by (\d+)/) {
+ my %ns = %screen;
+ for my $x (0 .. $w-1) {
+ my $sx = $x - $2;
+ $sx += $w if $sx < 0;
+ $ns{$x,$1} = $screen{$sx,$1};
+ }
+ %screen = %ns;
+ } elsif (/rotate column x=(\d+) by (\d+)/) {
+ my %ns = %screen;
+ for my $y (0 .. $h-1) {
+ my $sy = $y - $2;
+ $sy += $h if $sy < 0;
+ $ns{$1,$y} = $screen{$1,$sy};
+ }
+ %screen = %ns;
+ }
+}
+
+for my $y (0 .. $h-1) {
+ for my $x (0 .. $w-1) {
+ print $screen{$x,$y} ? '#' : ' ';
+ }
+ print "\n";
+}
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+chomp (my $in = <>);
+while ($in =~ /\((\d+)x(\d+)\)/g) {
+ my $p = pos($in) - length("($1x$2)");
+ my $str = substr($in, pos($in), $1);
+ my $repl = $str x $2;
+ say "repl=$repl";
+ substr($in, $p, length($str)+length("($1x$2)")) = $repl;
+ pos($in) = $p + length $repl;
+}
+
+say $in;
+say length $in;
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+sub str_len {
+ my ($in) = @_;
+ my $l = 0;
+ while ($in) {
+ $l++ while $in =~ s/\A[A-Z]//;
+ next if $in !~ /\A\((\d+)x(\d+)\)/;
+ my $str = substr($in, length("($1x$2)"), $1);
+ substr($in, 0, length("($1x$2)") + $1) = '';
+ my $c = $2;
+ $l += $c * str_len($str);
+ }
+ return $l;
+}
+
+chomp (my $in = <>);
+say str_len($in);
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my @bot_has;
+my @todo;
+my @outp;
+my @rule;
+while (<>) {
+ chomp;
+ if (/value (\d+) goes to bot (\d+)/) {
+ push @{ $bot_has[$2] }, $1;
+ push @todo, $2 if @{ $bot_has[$2] } == 2;
+ } elsif (/bot (\d+) gives low to (\w+) (\d+) and high to (\w+) (\d+)/) {
+ $rule[$1] = [ $2, $3, $4, $5 ];
+ } else {
+ die $_;
+ }
+}
+
+while (my $bot = shift @todo) {
+ my ($lo, $hi) = sort { $a <=> $b } @{ $bot_has[$bot] };
+ if ($lo == 17 && $hi == 61) {
+ say "$bot";
+ last;
+ }
+ my @r = @{ $rule[$bot] };
+ if ($r[0] eq 'output') {
+ $outp[$r[1]] = $lo;
+ } else {
+ push @{ $bot_has[$r[1]] }, $lo;
+ push @todo, $r[1] if @{ $bot_has[$r[1]] } == 2;
+ }
+
+ if ($r[2] eq 'output') {
+ $outp[$r[3]] = $hi;
+ } else {
+ push @{ $bot_has[$r[3]] }, $hi;
+ push @todo, $r[3] if @{ $bot_has[$r[3]] } == 2;
+ }
+}
+
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my @bot_has;
+my @todo;
+my @outp;
+my @rule;
+while (<>) {
+ chomp;
+ if (/value (\d+) goes to bot (\d+)/) {
+ push @{ $bot_has[$2] }, $1;
+ push @todo, $2 if @{ $bot_has[$2] } == 2;
+ } elsif (/bot (\d+) gives low to (\w+) (\d+) and high to (\w+) (\d+)/) {
+ $rule[$1] = [ $2, $3, $4, $5 ];
+ } else {
+ die $_;
+ }
+}
+
+while (defined(my $bot = shift @todo)) {
+ my ($lo, $hi) = sort { $a <=> $b } @{ $bot_has[$bot] };
+ say "evaluating bot $bot which has $lo and $hi";
+ if ($lo == 17 && $hi == 61) {
+ say "$bot";
+ }
+ my @r = @{ $rule[$bot] };
+ if ($r[0] eq 'output') {
+ $outp[$r[1]] = $lo;
+ say "output $r[1] => $lo";
+ } else {
+ push @{ $bot_has[$r[1]] }, $lo;
+ push @todo, $r[1] if @{ $bot_has[$r[1]] } == 2;
+ }
+
+ if ($r[2] eq 'output') {
+ $outp[$r[3]] = $hi;
+ say "output $r[3] => $hi";
+ } else {
+ push @{ $bot_has[$r[3]] }, $hi;
+ push @todo, $r[3] if @{ $bot_has[$r[3]] } == 2;
+ }
+}
+
+say $outp[0] * $outp[1] * $outp[2];
+