#!/usr/bin/perl -w

use strict;

$/ = "\n\n";

my $valid = 0;
while (<>) {
	my $correct = 0;
	for my $field (split /\s+/) {
		print "$field";
		$correct++
			if $field =~ /\Abyr:(\d{4})\z/
			&& $1 >= 1920 && $1 <= 2002;
		$correct++
			if $field =~ /\Aiyr:(\d{4})\z/
			&& $1 >= 2010 && $1 <= 2020;
		$correct++
			if $field =~ /\Aeyr:(\d{4})\z/
			&& $1 >= 2020 && $1 <= 2030;
		$correct++
			if $field =~ /\Ahgt:(\d+)(cm|in)\z/
			&& ($2 eq 'cm' && $1 >= 150 && $1 <= 193
			|| $2 eq 'in' && $1 >= 59 && $1 <= 76);
		$correct++
			if $field =~ /\Ahcl:#[a-f0-9]{6}\z/;
		$correct++
			if $field =~ /\Aecl:(?:amb|blu|brn|gry|grn|hzl|oth)\z/;
		$correct++
			if $field =~ /\Apid:(?:\d{9})\z/;
		print "\t$correct\n";
	}
	$valid++ if $correct >= 7;
	print "\n";
}

print "Valid: $valid\n";

