[2022][ruby][4.x] cleanup
change moxstumsqnworkqywyzqqpmqlzmzrxkw
commit 7a6670e5318728e8618077be0e034e004a6c916b
author Alpha Chen <alpha@kejadlen.dev>
date
parent topkvsxp
diff --git a/2022/ruby/day_04.rb b/2022/ruby/day_04.rb
index 53138c2..b57810e 100644
--- a/2022/ruby/day_04.rb
+++ b/2022/ruby/day_04.rb
@@ -1,6 +1,6 @@
-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)) }
+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) }}