Created
December 7, 2018 23:11
-
-
Save rooZzz/4a9ae3e6f479de1ac9479f2c815d8e08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Coordinate | |
attr_accessor :id, :x, :y, :area, :blacklisted | |
def initialize(x, y, id) | |
@id = id | |
@x = x | |
@y = y | |
@area = 0 | |
@blacklisted = false | |
end | |
end | |
ids = [*'a'..'z', *'A'..'Z'] | |
coordinates = File.read('input.txt').each_line.map do |line| | |
x, y = line.split(', ').map(&:to_i) | |
Coordinate.new(x, y, ids.shift) | |
end | |
max_x = coordinates.max_by(&:x).x | |
max_y = coordinates.max_by(&:y).y | |
region_area = 0 | |
(0..max_y).each do |y| | |
(0..max_x).each do |x| | |
total_distance = coordinates.map {|coordinate| (coordinate.x - x).abs + (coordinate.y - y).abs}.inject(:+) | |
region_area += 1 if total_distance < 10_000 | |
end | |
end | |
puts "Region area: #{region_area}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment