You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
advent-of-code/2022/ruby/day_04.rb

7 lines
344 B

p ARGF.read.lines(chomp: true)
.map { _1.split(?,) }
.map {|x| x.map { _1.split(?-).map(&:to_i) }}
.map {|(a,b),(x,y)| [(a..b), (x..y)] }
# .count {|a,b| (a.cover?(b.begin) && a.cover?(b.end)) || (b.cover?(a.begin) && b.cover?(a.end)) }
.count {|a,b| (a.cover?(b.begin) || a.cover?(b.end)) || (b.cover?(a.begin) || b.cover?(a.end)) }