Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature qw(say);
- use List::Util qw(all);
- sub chain (&@) {
- my $block = shift;
- return (map { &$block( $_[$_-1], $_[$_] ) } (1 .. $#_));
- }
- my $part1 = 0;
- foreach my $report (map { [m#(\d+)#g] } <>) {
- my @diffs = chain { $_[1] - $_[0] } @$report;
- $part1++ if (all { 1 <= abs($_) <= 3 && $diffs[0] * $_ > 0 } @diffs);
- }
- say "Part 1: $part1";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement