aboutsummaryrefslogtreecommitdiff
path: root/day04/part1.rb
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2022-12-04 12:41:13 +0000
committerNat Lasseter <user@4574.co.uk>2022-12-04 12:41:13 +0000
commit408c7a8b7dce5246a595b7737de6a1b7825a53b8 (patch)
tree49976281d51f0ac58d6c3aed3817bf302ca333ab /day04/part1.rb
parentc62e6e28ad065948557aea88958631462a42b1ec (diff)
Day 04
Diffstat (limited to 'day04/part1.rb')
-rw-r--r--day04/part1.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/day04/part1.rb b/day04/part1.rb
new file mode 100644
index 0000000..529572c
--- /dev/null
+++ b/day04/part1.rb
@@ -0,0 +1,9 @@
+pairs = $stdin.readlines.map { |line|
+ line.strip.split(?,).map { |range|
+ Range.new(*range.split(?-).map(&:to_i))
+ }
+}
+
+puts pairs.select { |a, b|
+ a.cover?(b) || b.cover?(a)
+}.count