-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgear.rb
41 lines (36 loc) · 958 Bytes
/
gear.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true
module AdventOfCode
module Puzzles2023
module Day03
##
# Class for representing a gear
class Gear
##
# @return [String] symbol of the gear
attr_reader :symbol
##
# @return [String] index of the gear
attr_reader :index
##
# @return [Array<Integer>] array of numbers of the gear
attr_reader :numbers
##
# @param symbol [String] symbol of the gear
# @param index [String] index of the gear
# @param numbers [Array<Integer>] array of numbers of the gear
def initialize(symbol:, index:, numbers:)
@symbol = symbol
@index = index
@numbers = numbers
end
##
# Get the ratio of the gear.
#
# @return [Integer] ratio of the gear
def ratio
@ratio ||= numbers.reduce(:*)
end
end
end
end
end