Solved Day 4

main
s00ner 2022-12-04 10:30:10 -05:00
parent f226fd7429
commit a78bc48338
2 changed files with 1026 additions and 0 deletions

1000
day04/input Normal file

File diff suppressed because it is too large Load Diff

26
day04/solution.rb Executable file
View File

@ -0,0 +1,26 @@
#!/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