import std.stdio; import std.file; import std.array; import std.uni : isWhite; void main() { string contents = readText("input"); auto lines = contents.split("\n\n"); int good = 0; foreach(i, line; lines) { auto parts = line.split!(isWhite); string[] items = [ "byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid" ]; int[string] totals; foreach(y, item; items) totals[item] = 0; foreach(x, part; parts) { auto fields = part.split(":"); if(fields.length < 2) continue; if(!(fields[0] in totals)) continue; totals[fields[0]]++; } int sum = 0; foreach(z, total; totals) sum += total; if(sum == items.length) good++; } writefln("There are %d valid passports.", good); }