From 3db1c4c37290a1d08308b9b0a48b01ead93e59c5 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 8 Dec 2025 03:32:55 +0000 Subject: [PATCH] delegate each_with_index --- day_07/2.rb | 12 ++++++------ day_07/graph.rb | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/day_07/2.rb b/day_07/2.rb index 2f583f7..7357975 100755 --- a/day_07/2.rb +++ b/day_07/2.rb @@ -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) == "^" diff --git a/day_07/graph.rb b/day_07/graph.rb index 7e04549..1b2405b 100644 --- a/day_07/graph.rb +++ b/day_07/graph.rb @@ -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|