You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
897 B

package day04
import (
"log"
"regexp"
)
func Solve2() {
counter := 0
validations := map[string]string{
// Validate Birth year (1920-2002)
"byr": `^(19[2-8][0-9]|199[0-9]|200[0-2])$`,
// Validate Issue year (2010-2020)
"iyr": `^(201[0-9]|2020)$`,
// Validate Expiration year (2020-2030)
"eyr": `^(202[0-9]|2030)$`,
// Validate height (59-76in) or (150-193cm)
"hgt": `^((59|6[0-9]|7[0-6])in|(1[5-8][0-9]|19[0-3])cm)$`,
// Validate Hair color
"hcl": `^#[0-9a-f]{6}$`,
// Validate Eye color
"ecl": `^(amb|blu|brn|gry|grn|hzl|oth)$`,
// Validate Passport ID
"pid": `^[0-9]{9}$`,
}
for _, row := range rows {
valid := true
for key, reg := range validations {
if regexp.MustCompile(reg).FindString(row[key]) == "" {
valid = false
}
}
if valid {
counter++
}
}
// Correct answer: 127
log.Println("2020-12-04.02: Answer:", counter)
}