Skip to content

Instantly share code, notes, and snippets.

@rooZzz
Created December 7, 2018 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rooZzz/4a9ae3e6f479de1ac9479f2c815d8e08 to your computer and use it in GitHub Desktop.
Save rooZzz/4a9ae3e6f479de1ac9479f2c815d8e08 to your computer and use it in GitHub Desktop.
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