Solved Day 4
parent
f226fd7429
commit
a78bc48338
File diff suppressed because it is too large
Load Diff
|
@ -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
|
Loading…
Reference in New Issue