Log in to get your input and submit your answers.

Day 04: Profile Processing

After securing a seat in the cluster, you head down to grab a coffee. But when attempting to pass back through 42's security turnstiles, disaster strikes: the badge scanner crashed following a script update by Le Bocal.

Instead of validating badges normally, the terminal dumps raw student profile logs onto the screen. The queue is stretching down the street and you need to write a script to determine who is allowed in.

Each profile's data is represented as a sequence of key:value pairs separated by spaces or newlines. Profiles are separated by a blank line.

A valid profile must contain the following fields:

Part 1

The Bocal informs you that the system is erroneously rejecting visiting students from other campuses. To prevent a riot at the doors, the workaround rule is: the cid field is optional. All other fields are strictly mandatory.

Example

You grab a sample of logs on the fly:

ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm

iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
hcl:#cfa07d byr:1929

hcl:#ae17e1 iyr:2013
eyr:2024
ecl:brn pid:760753108 byr:1931
hgt:179cm

hcl:#cfa07d eyr:2025 pid:166559648
iyr:2011 ecl:brn hgt:59in

In this example, the first profile is valid (all 8 fields present). The second is invalid (missing hgt). The third is valid (missing cid, which is allowed). The fourth is invalid (missing byr).

In this sample, there are 2 valid profiles.

You are handed the USB drive containing the full log file. How many profiles are valid?