m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/04/a.rb
diff options
context:
space:
mode:
Diffstat (limited to '04/a.rb')
-rw-r--r--04/a.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/04/a.rb b/04/a.rb
new file mode 100644
index 0000000..27f7959
--- /dev/null
+++ b/04/a.rb
@@ -0,0 +1,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