AoC2022/day04/solution.rb

27 lines
670 B
Ruby
Executable File

#!/bin/env ruby
# frozen_string_literal: true
require 'pry'
assignments = File.readlines('./input').map(&:strip).map do |assignment|
assignment.split(',').map { |pair| pair.split('-').map(&:to_i) }
end
solution = assignments.map do |first, second|
first = (first[0]..first[1])
second = (second[0]..second[1])
(first.cover?(second) || second.cover?(first))
end
puts "Part 1 solution #{solution.count(true)}"
# #Part 2
solution2 = assignments.map do |first, second|
first = (first[0]..first[1])
second = (second[0]..second[1])
(first.cover?(second.first) || second.cover?(first.first))
end
puts "Part 2 Solution #{solution2.count(true)}"
# binding.pry