package main
import (
"log"
"strconv"
"strings"
"unicode"
)
func byrValid(in string) bool {
i, err := strconv.Atoi(in)
if err != nil {
log.Println(err)
return false
}
return i <= 2002 && i >= 1920
}
func iyrValid(in string) bool {
i, err := strconv.Atoi(in)
if err != nil {
log.Println(err)
return false
}
return i <= 2020 && i >= 2010
}
func eyrValid(in string) bool {
i, err := strconv.Atoi(in)
if err != nil {
log.Println(err)
return false
}
return i <= 2030 && i >= 2020
}
func hgtValid(in string) bool {
var inch, centim bool
switch {
case strings.HasSuffix(in, "cm"):
centim = true
case strings.HasSuffix(in, "in"):
inch = true
default:
return false
}
in = strings.TrimRight(in, "in")
in = strings.TrimRight(in, "cm")
i, err := strconv.Atoi(in)
if err != nil {
log.Println(err, in)
return false
}
switch {
case inch:
return i >= 59 && i <= 76
case centim:
return i >= 150 && i <= 193
default:
log.Println("unreachable")
return false
}
}
func hclValid(in string) bool {
for i, ch := range in {
if i == 0 {
if ch != '#' {
return false
}
continue
}
if !unicode.IsDigit(ch) && !(ch >= 'a' && ch <= 'f') {
return false
}
}
return true
}
func eclValid(in string) bool {
vld := []string{"amb", "blu", "brn", "gry", "grn", "hzl", "oth"}
for _, v := range vld {
if v == in {
return true
}
}
return false
}
func pidValid(in string) bool {
if len(in) != 9 {
return false
}
for _, ch := range in {
if !unicode.IsDigit(ch) {
return false
}
}
return true
}