mirror of
https://github.com/onyx-and-iris/aoc2025.git
synced 2025-12-08 19:57:48 +00:00
delegate each_with_index
This commit is contained in:
parent
22afdfb126
commit
3db1c4c372
12
day_07/2.rb
12
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) == "^"
|
||||
|
||||
@ -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|
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user