m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/04/a.rb
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-12-25 15:14:20 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-12-25 15:14:20 +0100
commit8216a91439c30ba2c6f57a49be2daef7ec6e596c (patch)
treea05cb67d42211aacbcf2b9fada606d8213c233ed /04/a.rb
parentd4792ef0e009a6c6f58d01e8387ac3cceb8c9687 (diff)
Add day 4
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