diff options
author | Nat Lasseter <user@4574.co.uk> | 2022-12-04 12:41:13 +0000 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2022-12-04 12:41:13 +0000 |
commit | 408c7a8b7dce5246a595b7737de6a1b7825a53b8 (patch) | |
tree | 49976281d51f0ac58d6c3aed3817bf302ca333ab /day04/part2.rb | |
parent | c62e6e28ad065948557aea88958631462a42b1ec (diff) |
Day 04
Diffstat (limited to 'day04/part2.rb')
-rw-r--r-- | day04/part2.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/day04/part2.rb b/day04/part2.rb new file mode 100644 index 0000000..d02c1e2 --- /dev/null +++ b/day04/part2.rb @@ -0,0 +1,15 @@ +class Range + def overlap?(other) + cover?(other.first) || other.cover?(first) + end +end + +pairs = $stdin.readlines.map { |line| + line.strip.split(?,).map { |range| + Range.new(*range.split(?-).map(&:to_i)) + } +} + +puts pairs.select { |a, b| + a.overlap?(b) +}.count |