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
248 B

p ARGF.read
.scan(/(\d+)-(\d+),(\d+)-(\d+)/)
.map { _1.map(&:to_i) }
.map {|a,b,c,d| [(a..b), (c..d)] }
# .count {|a,b| a.cover?(b) || b.cover?(a) } # part 1
.count {|a,b| a.minmax.any? { b.cover?(_1) } || b.minmax.any? { a.cover?(_1) }}