Skip to content

Instantly share code, notes, and snippets.

@darkash
Created December 16, 2020 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darkash/8cf36d1c52129bd054ce05b5a1bc629f to your computer and use it in GitHub Desktop.
Save darkash/8cf36d1c52129bd054ce05b5a1bc629f to your computer and use it in GitHub Desktop.
AoC 2020 (Day 4)
required = %w[byr iyr eyr hgt hcl ecl pid]
optional = %w[cid]
input = "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".split("\n\n").map {|line| line.split("\n").join(" ") }
input.select do |x|
fields = x.scan(/(\S+):/).flatten
required.map { |r| fields.include?(r) }.to_set.count == 1
end.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment