Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use v5.32;
- use warnings;
- my @inside;
- 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);
- }
- # Mark how many of b's ends are inside a's range
- $inside[($as <= $bs <= $ae) + ($as <= $be <= $ae)]++;
- }
- print "Part 1: ", $inside[2], "\n";
- print "Part 2: ", $inside[1] + $inside[2], "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement