delegate each_with_index

This commit is contained in:
onyx-and-iris 2025-12-08 03:32:55 +00:00
parent 22afdfb126
commit 3db1c4c372
2 changed files with 7 additions and 7 deletions

View File

@ -5,18 +5,18 @@ require_relative "graph"
class Main
def run
lines = $stdin.readlines(chomp: true)
graph = Graph.new(lines)
input = $stdin.readlines(chomp: true)
graph = Graph.new(input)
counts = Hash.new(0)
counts[graph.start.x] = 1
process_graph(lines, graph, counts)
process_graph(graph, counts)
puts counts.values.sum
end
def process_graph(lines, graph, counts)
lines.each_with_index do |line, y|
line.chars.each_with_index do |char, x|
def process_graph(graph, counts)
graph.each_with_index do |line, y|
line.each_with_index do |char, x|
current = Point.new(x, y)
next unless graph.at(current) == "^"

View File

@ -5,7 +5,7 @@ require_relative "point"
class Graph
attr_reader :start, :height, :width
extend Forwardable
def_delegators :@data, :[]
def_delegators :@data, :[], :each_with_index
def initialize(input)
@data = input.each_with_index.map do |line, y|