--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+chomp (my $data = <>);
+
+$data =~s /\A(.)(.*)\z/\1\2\1/;
+my $sum = 0;
+$sum += $1 while $data =~ /(.)(?=\1)/g;
+say $sum;
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+chomp (my $data = <>);
+
+my $l = length $data;
+$l /= 2;
+$data .= substr($data, 0, $l);
+$l--;
+my $sum = 0;
+$sum += $1 while $data =~ /(.)(?=.{$l}\1)/g;
+say $sum;
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+use List::Util qw(min max);
+
+my $res = 0;
+while (<>) {
+ my @a = split /\s+/;
+ my $m1 = min @a;
+ my $m2 = max @a;
+ $res += $m2-$m1;
+}
+
+say $res;
+
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+use List::Util qw(min max);
+
+my $res = 0;
+while (<>) {
+ my @a = split /\s+/;
+ for my $i (0 .. $#a) {
+ for my $j (0 .. $#a) {
+ next if $i == $j;
+ if (int ($a[$i]/$a[$j])*$a[$j] == $a[$i]) {
+ $res += $a[$i]/$a[$j];
+ }
+ } }
+}
+
+say $res;
+
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+my $in = 368078;
+
+my $diam = 0;
+$diam++ while $in > (2*$diam+1)*(2*$diam+1);
+my $dist = 2*$diam-1;
+my $dir = -1;
+my $i = (2*$diam-1)*(2*$diam-1)+1;
+while ($i < $in) {
+ # say "\t$i $dist $dir";
+ if ($dist <= $diam) {
+ $dir = 1;
+ } elsif ($dist > 2*$diam-1) {
+ $dir = -1;
+ }
+ $dist += $dir;
+ $i++;
+}
+
+say $dist;
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+my $in = 368078;
+
+my ($x, $y) = (1, 0);
+my $r = 1;
+$; = ',';
+my %map = ("0,0" => 1);
+sub set {
+ my ($x, $y) = @_;
+ my $sum = 0;
+ for my $dx (-1 .. 1) {
+ for my $dy (-1 .. 1) {
+ $sum += $map{$x+$dx,$y+$dy} if defined
+ $map{$x+$dx,$y+$dy};
+ } }
+ $map{$x,$y} = $sum;
+
+ say "$x, $y = ", $sum;
+ exit 0 if $sum > $in;
+}
+
+while (1) {
+ for my $i (0 .. 2*$r-1) {
+ set($x, $y-$i);
+ }
+ $y -= 2*$r-1;
+ for my $i (1 .. 2*$r) {
+ set($x-$i, $y);
+ }
+ $x -= 2*$r;
+ for my $i (1 .. 2*$r) {
+ set($x, $y+$i);
+ }
+ $y += 2*$r;
+ for my $i (1 .. 2*$r) {
+ set($x+$i, $y);
+ }
+ $x += 2*$r+1;
+ $r++;
+}
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+my $valid = 0;
+LINE:
+while (<>) {
+ chomp;
+ my %seen;
+ for my $w (split /\s+/) {
+ next LINE if $seen{$w}++;
+ }
+ $valid++;
+}
+
+say $valid;
+
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+my $valid = 0;
+LINE:
+while (<>) {
+ chomp;
+ my %seen;
+ for my $w (split /\s+/) {
+ my $w1 = join('', sort split //, $w);
+ next LINE if $seen{$w1}++;
+ }
+ $valid++;
+}
+
+say $valid;
+
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+
+my $pc = 0;
+chomp (my @offs = <>);
+
+my $steps = 0;
+while ($pc >= 0 && $pc < @offs) {
+ say "$steps $pc $offs[$pc]";
+ $pc += $offs[$pc]++;
+ $steps++;
+}
+
+say $steps;
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+
+my $pc = 0;
+chomp (my @offs = <>);
+
+my $steps = 0;
+while ($pc >= 0 && $pc < @offs) {
+ # say "$steps $pc $offs[$pc]";
+ my $off = $offs[$pc];
+ if ($off >= 3) {
+ $offs[$pc]--;
+ } else {
+ $offs[$pc]++;
+ }
+ $pc += $off;
+ $steps++;
+}
+
+say $steps;
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+chomp (my @banks = split /\s+/, <>);
+
+my %seen;
+my $steps;
+while (1) {
+ my $key = join(',', @banks);
+ last if $seen{$key};
+ $steps++;
+ my ($max, $maxi);
+ for my $i (0 .. $#banks) {
+ if ($banks[$i] > $max) {
+ $max = $banks[$i];
+ $maxi = $i;
+ }
+ }
+ $banks[$maxi] = 0;
+ while ($max--) {
+ $maxi = 0 if ++$maxi > $#banks;
+ $banks[$maxi]++;
+ }
+}
+say $steps;
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+chomp (my @banks = split /\s+/, <>);
+
+my %seen;
+my $steps;
+my $another;
+while (1) {
+ my $key = join(',', @banks);
+ last if defined $another && $another eq $key;
+ if ($seen{$key}++ && !defined $another) {
+ $another = $key;
+ $steps = 0;
+ }
+ $steps++;
+ my ($max, $maxi);
+ for my $i (0 .. $#banks) {
+ if ($banks[$i] > $max) {
+ $max = $banks[$i];
+ $maxi = $i;
+ }
+ }
+ $banks[$maxi] = 0;
+ while ($max--) {
+ $maxi = 0 if ++$maxi > $#banks;
+ $banks[$maxi]++;
+ }
+}
+say $steps;
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+my %all;
+my %below;
+my %top;
+
+while (<>) {
+ my ($name, $num, $rest) = /^(\w+) \((\d+)\)(.*)/;
+ $all{$name} = $num;
+ next if !length $rest;
+ for my $t ($rest =~ /(\w+)/g) {
+ $below{$t} = $name;
+ $top{$t} = 1;
+ }
+}
+
+for my $node (keys %all) {
+ say $node if !$top{$node};
+}
+
+
+
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+my %all;
+my %above;
+my %top;
+
+while (<>) {
+ my ($name, $num, $rest) = /^(\w+) \((\d+)\)(.*)/;
+ $all{$name} = $num;
+ next if !length $rest;
+ for my $t ($rest =~ /(\w+)/g) {
+ push @{ $above{$name} }, $t;
+ $top{$t} = 1;
+ }
+}
+
+my $start = 'uownj';
+
+sub walk {
+ my ($node) = @_;
+ my %sizes;
+ return $all{$node}
+ if !exists $above{$node};
+
+ my $sum;
+ my %nodes;
+ for my $ab (@{ $above{$node} }) {
+ my $s = walk($ab);
+ $sum += $s;
+ $sizes{$s}++;
+ $nodes{$s} = $ab;
+ }
+ my @sizes = sort { $sizes{$a} <=> $sizes{$b} } keys %sizes;
+ if (@sizes == 1) {
+ return $sum + $all{$node};
+ } else {
+ say $all{$nodes{$sizes[0]}} + $sizes[1]-$sizes[0];
+ exit 0;
+ }
+}
+
+walk('uownj');
+
+
+
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+
+my %regs;
+while (<>) {
+ chomp;
+ my ($reg, $op, $val, $creg, $cop, $cval) =
+ /^(\w+) (\S\Sc) (-?\d+) if (\w+) (\S+) (-?\d+)/;
+ $regs{$reg} //= 0;
+ $regs{$creg} //= 0;
+ say "$reg $op $val $creg $cop $cval";
+ if ($cop eq '<' && $regs{$creg} < $cval
+ || $cop eq '>' && $regs{$creg} > $cval
+ || $cop eq '==' && $regs{$creg} == $cval
+ || $cop eq '!=' && $regs{$creg} != $cval
+ || $cop eq '<=' && $regs{$creg} <= $cval
+ || $cop eq '>=' && $regs{$creg} >= $cval) {
+ if ($op eq 'inc') {
+ $regs{$reg} += $val;;
+ } else {
+ $regs{$reg} -= $val;
+ }
+ }
+}
+
+use List::Util qw(max);
+
+say max values %regs;
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+use List::Util qw(max);
+
+my %regs;
+my $max;
+while (<>) {
+ chomp;
+ my ($reg, $op, $val, $creg, $cop, $cval) =
+ /^(\w+) (\S\Sc) (-?\d+) if (\w+) (\S+) (-?\d+)/;
+ $regs{$reg} //= 0;
+ $regs{$creg} //= 0;
+ say "$reg $op $val $creg $cop $cval";
+ if ($cop eq '<' && $regs{$creg} < $cval
+ || $cop eq '>' && $regs{$creg} > $cval
+ || $cop eq '==' && $regs{$creg} == $cval
+ || $cop eq '!=' && $regs{$creg} != $cval
+ || $cop eq '<=' && $regs{$creg} <= $cval
+ || $cop eq '>=' && $regs{$creg} >= $cval) {
+ if ($op eq 'inc') {
+ $regs{$reg} += $val;;
+ } else {
+ $regs{$reg} -= $val;
+ }
+ }
+ my $m = max values %regs;
+ $max = $m if !$max || $max < $m;
+}
+
+say $max;
+
+
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+chomp (my $stream = <>);
+
+1 while $stream =~ s/<[^!>]*!./</;
+1 while $stream =~ s/<[^>]*?>//;
+
+my $sum;
+my $depth = 0;
+for my $c (split //, $stream) {
+ if ($c eq '{') {
+ $depth++;
+ } elsif ($c eq '}') {
+ $sum += $depth--;
+ }
+}
+
+say $sum;
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+chomp (my $stream = <>);
+
+my $glen;
+1 while $stream =~ s/<([^!>]*)!./<$1/;
+1 while $stream =~ s/<([^>]*?)>/$glen += length $1/e;
+say $glen;
+
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+my @l = split /[,\s]/, <>;
+
+my $pos = 0;
+my $skip = 0;
+# my @nodes = (0 .. 4);
+my @nodes = (0 .. 255);
+my $n = @nodes;
+
+for my $i (@l) {
+ my $end = $pos + $i;
+ my @to_rev;
+ say "pos=$pos skip $skip i=$i ", join(',', @nodes);
+ if ($end > $n) {
+ push @to_rev, splice @nodes, $pos;
+ push @to_rev, splice @nodes, 0, $end - $n;
+ @to_rev = reverse @to_rev;
+ say "to_rev = ", join(',', @to_rev);
+ unshift @nodes, splice @to_rev, @to_rev-($end-$n);
+ push @nodes, @to_rev;
+ } else {
+ push @to_rev, splice @nodes, $pos, $i;
+ splice @nodes, $pos, 0, reverse @to_rev;
+ }
+ $pos += $i + $skip++;;
+ $pos -= $n while $pos >= $n;
+}
+
+say join(',',@nodes);
+
+say $nodes[0] * $nodes[1];
--- /dev/null
+#!/usr/bin/perl
+
+use v5.30;
+use strict;
+
+chomp(my $line = <>);
+my @l = map { ord } split //, $line;
+push @l, 17, 31, 73, 47, 23;
+
+my $pos = 0;
+my $skip = 0;
+# my @nodes = (0 .. 4);
+my @nodes = (0 .. 255);
+my $n = @nodes;
+
+for (1 .. 64) {
+for my $i (@l) {
+ my $end = $pos + $i;
+ my @to_rev;
+ say "pos=$pos skip $skip i=$i ", join(',', @nodes);
+ if ($end > $n) {
+ push @to_rev, splice @nodes, $pos;
+ push @to_rev, splice @nodes, 0, $end - $n;
+ @to_rev = reverse @to_rev;
+ say "to_rev = ", join(',', @to_rev);
+ unshift @nodes, splice @to_rev, @to_rev-($end-$n);
+ push @nodes, @to_rev;
+ } else {
+ push @to_rev, splice @nodes, $pos, $i;
+ splice @nodes, $pos, 0, reverse @to_rev;
+ }
+ $pos += $i + $skip++;
+ $pos -= $n while $pos >= $n;
+}
+}
+
+my $hash = '';
+while (my @s = splice (@nodes, 0, 16)) {
+ my $x = 0;
+ $x ^= $_ for @s;
+ $hash .= sprintf("%02x", $x);
+}
+say $hash;