Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use v5.32;
- use warnings;
- my $part1 = 0;
- my $part2 = 0;
- foreach (map { [split /\D/] } <>) {
- my ($as, $ae, $bs, $be) = @$_;
- # Make sure larger range is in as-ae, smaller in bs-be
- if (($ae - $as) < ($be - $bs)) {
- ($as, $ae, $bs, $be) = ($bs, $be, $as, $ae);
- }
- # Bigger range outside smaller:
- $part1++ if ($as <= $bs and $ae >= $be);
- # At least one end of smaller inside bigger:
- $part2++ if ($as <= $bs <= $ae or $as <= $be <= $ae);
- }
- print "Part 1: $part1\n";
- print "Part 2: $part2\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement