m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/04/a.rb
blob: 27f7959798e7ebaad814cf06a464234570e08c48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
file = File.read('input.txt')
records = file.split "\n\n"

fields = [ 'byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid' ]

count = 0
records.each do |record|
  fields_seen = 0
  entries = record.split
  entries.each do |entry|
    f, _ = entry.split ':' 
    if fields.include?(f)
      fields_seen += 1
    end
  end
  if fields_seen == 7
    count += 1
  end
end
puts count