aoc2025/day_07/graph.rb

33 lines
636 B
Ruby

require "forwardable"
require_relative "point"
class Graph
attr_reader :start, :height, :width
extend Forwardable
def_delegators :@data, :[], :each_with_index
def initialize(input)
@data = input.each_with_index.map do |line, y|
if y.zero?
@start = Point.new(line.index("S"), y)
end
line.chars
end
@width = @data[0].size - 1
@height = @data.size - 1
end
def to_s
@data.map { |row| row.join("") }.join("\n")
end
def at(point)
@data[point.y][point.x]
end
def out_of_bounds?(point)
point.x < 0 || point.x > @width || point.y < 0 || point.y > @height
end
end