--- /dev/null
+#!/usr/bin/perl -w
+
+use v5.16;
+
+my $p;
+my $count;
+while (<>) {
+ my ($x1, $y1, $x2, $y2) = /(\d+),(\d+) -> (\d+),(\d+)/;
+ next if $x1 != $x2 && $y1 != $y2;
+ if ($x1 != $x2) {
+ if ($x1 > $x2) {
+ ($x1, $x2) = ($x2, $x1);
+ }
+ for my $x ($x1 .. $x2) {
+ $count++ if ++$p->{$x}->{$y1} == 2;
+ }
+ } else {
+ if ($y1 > $y2) {
+ ($y1, $y2) = ($y2, $y1);
+ }
+ for my $y ($y1 .. $y2) {
+ $count++ if ++$p->{$x1}->{$y} == 2;
+ }
+ }
+}
+
+say $count;
+
--- /dev/null
+#!/usr/bin/perl -w
+
+use v5.16;
+
+my $p;
+my $count;
+while (<>) {
+ my ($x1, $y1, $x2, $y2) = /(\d+),(\d+) -> (\d+),(\d+)/;
+ # say " $x1, $y1 -> $x2, $y2";
+ my $xi = $x2 > $x1 ? 1 : $x2 == $x1 ? 0 : -1;
+ my $yi = $y2 > $y1 ? 1 : $y2 == $y1 ? 0 : -1;
+ # say " $xi, $yi";
+
+ my ($x, $y) = ($x1, $y1);
+ do {
+ # say "$x, $y";
+ $count++ if ++$p->{$x}->{$y} == 2;
+ $x += $xi; $y += $yi;
+ } while ($x != $x2+$xi || $y != $y2+$yi);
+}
+
+say $count;
+