stolen.jl 886 B

1234567891011121314151617181920212223
  1. function part2(data)
  2. fields = Dict(
  3. "byr" => x-> (n = tryparse(Int, x); !isnothing(n) && 1920<=n<=2002),
  4. "iyr" => x-> (n = tryparse(Int, x); !isnothing(n) && 2010<=n<=2020),
  5. "eyr" => x-> (n = tryparse(Int, x); !isnothing(n) && 2020<=n<=2030),
  6. "hgt" => x->
  7. if endswith(x, "cm")
  8. height = parse(Int, replace(x, "cm"=>""))
  9. 150 <= height <= 193
  10. elseif endswith(x, "in")
  11. height = parse(Int, replace(x, "in"=>""))
  12. 59 <= height <= 76
  13. else
  14. false
  15. end,
  16. "hcl" => x->!isnothing(match(r"^#[0-9a-f]{6}$"i, x)),
  17. "ecl" => x->x ∈ ["amb", "blu", "brn", "gry", "grn", "hzl", "oth"],
  18. "pid" => x->!isnothing(match(r"^\d{9}$", x)),
  19. )
  20. (data .|> x->all([cond(get(x, key, "")) for (key, cond) in fields])) |> sum
  21. end
  22. part2(b)