sol1.pl (444B) [raw]
1 #!/usr/bin/env perl 2 use strict; 3 use warnings; 4 5 open(my $fh, '<', 'input') or die "$!"; 6 # slurp 7 my $content; 8 { 9 local $/; 10 $content = <$fh>; 11 } 12 13 my @recs = split("\n\n", $content); 14 my $n; 15 my @required = qw(byr iyr eyr hgt hcl ecl pid); 16 REC: 17 for my $r (@recs) { 18 19 my @fields = split(/\s+/, $r); 20 my %has = map { $_ => 1 } map { $_ =~ s/:.*//r } @fields; 21 for my $req (@required) { 22 next REC if !exists $has{$req}; 23 } 24 $n++; 25 } 26 print "$n\n";