From 27d0c1a07960f4080fd3032e97f25f4ad02b0e73 Mon Sep 17 00:00:00 2001
From: "Jan \"Yenya\" Kasprzak" <kas@fi.muni.cz>
Date: Wed, 13 Dec 2023 07:42:48 +0100
Subject: [PATCH] Day 13: off-by-one errors, quite ugly

---
 2023/25.pl | 55 ++++++++++++++++++++++++++++++
 2023/26.pl | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+)
 create mode 100755 2023/25.pl
 create mode 100755 2023/26.pl

diff --git a/2023/25.pl b/2023/25.pl
new file mode 100755
index 0000000..24e02dd
--- /dev/null
+++ b/2023/25.pl
@@ -0,0 +1,55 @@
+#!/usr/bin/perl -w
+
+use v5.38;
+use experimental 'multidimensional', 'for_list', 'builtin';
+use builtin 'indexed';
+use List::Util;
+use Y::AoC::Task;
+$; = ';';
+# t;
+
+$/ = "\n\n";
+
+my $sum;
+MAP:
+while (<>) {
+	chomp;
+	my @map = map { [ split // ] } split /\n/, $_;
+
+	say "============ $#{ $map[0] } x $#map ==========";
+	COL:
+	for my $r1 (1 .. $#{ $map[0] }) {
+		say "Trying col $r1";
+		for my $x (0 .. $r1) {
+			my $x1 = 2*$r1-$x-1;
+			say "col $x vs $x1";
+			next if $x1 > $#{ $map[0] };
+			for my $y (0 .. $#map) {
+				next COL if $map[$y][$x] ne $map[$y][$x1];
+			}
+		}
+		say "X match at $r1";
+		$sum += $r1;
+		next MAP;
+	}
+	ROW:
+	for my $r1 (1 .. $#map) {
+		say "Trying row $r1";
+		for my $y (0 .. $r1) {
+			my $y1 = 2*$r1-$y-1;
+			say "row $y vs $y1";
+			next if $y1 > $#map;
+			for my $x (0 .. $#{ $map[0] }) {
+				next ROW if $map[$y][$x] ne $map[$y1][$x];
+			}
+		}
+		say "Y match at $r1";
+		$sum += 100*$r1;
+		next MAP;
+	}
+	die "No match at $.";
+}
+
+say $sum;
+
+
diff --git a/2023/26.pl b/2023/26.pl
new file mode 100755
index 0000000..e577106
--- /dev/null
+++ b/2023/26.pl
@@ -0,0 +1,98 @@
+#!/usr/bin/perl -w
+
+use v5.38;
+use experimental 'multidimensional', 'for_list', 'builtin';
+use builtin 'indexed';
+use List::Util;
+use Y::AoC::Task;
+$; = ';';
+# t;
+
+$/ = "\n\n";
+
+my $sum;
+MAP:
+while (<>) {
+	chomp;
+	my @map = map { [ split // ] } split /\n/, $_;
+	
+	my $n;
+	COL:
+	for my $r1 (1 .. $#{ $map[0] }) {
+		say "Trying col $r1";
+		for my $x (0 .. $r1) {
+			my $x1 = 2*$r1-$x-1;
+			say "col $x vs $x1";
+			next if $x1 > $#{ $map[0] };
+			for my $y (0 .. $#map) {
+				next COL if $map[$y][$x] ne $map[$y][$x1];
+			}
+		}
+		say "X match at $r1";
+		$n += $r1;
+		goto OUT;
+	}
+	ROW:
+	for my $r1 (1 .. $#map) {
+		say "Trying row $r1";
+		for my $y (0 .. $r1) {
+			my $y1 = 2*$r1-$y-1;
+			say "row $y vs $y1";
+			next if $y1 > $#map;
+			for my $x (0 .. $#{ $map[0] }) {
+				next ROW if $map[$y][$x] ne $map[$y1][$x];
+			}
+		}
+		say "Y match at $r1";
+		$n = 100*$r1;
+		goto OUT;
+	}
+	OUT:
+	
+	for my $sx (0 .. $#{ $map[0] }) {
+		for my $sy (0 .. $#map) {
+			my $old = $map[$sy][$sx];
+			$map[$sy][$sx] = ($old eq '.') ? '#' : '.';
+			say "######################### $sx,$sy $old $map[$sy][$sx]";
+	say "============ $#{ $map[0] } x $#map ==========";
+	COL:
+	for my $r1 (1 .. $#{ $map[0] }) {
+		next if $n == $r1;
+		say "Trying col $r1";
+		for my $x (0 .. $r1) {
+			my $x1 = 2*$r1-$x-1;
+			say "col $x vs $x1";
+			next if $x1 > $#{ $map[0] };
+			for my $y (0 .. $#map) {
+				next COL if $map[$y][$x] ne $map[$y][$x1];
+			}
+		}
+		say "X match at $r1";
+		$sum += $r1;
+		next MAP;
+	}
+	ROW:
+	for my $r1 (1 .. $#map) {
+		next if $n == 100*$r1;
+		say "Trying row $r1";
+		for my $y (0 .. $r1) {
+			my $y1 = 2*$r1-$y-1;
+			say "row $y vs $y1";
+			next if $y1 > $#map;
+			for my $x (0 .. $#{ $map[0] }) {
+				next ROW if $map[$y][$x] ne $map[$y1][$x];
+			}
+		}
+		say "Y match at $r1";
+		$sum += 100*$r1;
+		next MAP;
+	}
+			$map[$sy][$sx] = $old;
+		}
+	}
+	die "No match at $.";
+}
+
+say $sum;
+
+
-- 
2.43.5