#!/usr/local/bin/perl # day 2022-04 use strict; use warnings; use v5.32; @ARGV = "input" unless @ARGV; chomp( my $input = do { local $/; <> } ); my $part1 = 0; my $part2 = 0; foreach ( split /\n/, $input ) { my ( $x1, $y1, $x2, $y2 ) = m/(\d+)-(\d+),(\d+)-(\d+)/; $part1++ if ( ( $x1 >= $x2 && $y1 <= $y2 ) || ( $x2 >= $x1 && $y2 <= $y1 ) ); $part2++ if ( ( $y2 >= $x1 && $y2 <= $y1 ) || ( $x2 >= $x1 && $x2 <= $y1 ) || ( $x1 >= $x2 && $y1 <= $y2 ) ); } say "part 1: ", $part1; say "part 2: ", $part2;