-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set.rb
44 lines (38 loc) · 1.04 KB
/
set.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
42
43
44
# frozen_string_literal: true
module AdventOfCode
module Puzzles2023
module Day02
##
# Set class to store the number of blue, green, and red cubes.
class Set
##
# @return [Integer] number of blue cubes
attr_reader :blue
##
# @return [Integer] number of green cubes
attr_reader :green
##
# @return [Integer] number of red cubes
attr_reader :red
##
# @param blue [Integer] number of blue cubes
# @param green [Integer] number of green cubes
# @param red [Integer] number of red cubes
def initialize(blue: 0, green: 0, red: 0)
@blue = blue
@green = green
@red = red
end
##
# Compute the power of the set by multiplying the number of
# blue, green, and red cubes.
#
# @return [Integer] power of the set
def power
return @power if @power
@power = (blue || 1) * (green || 1) * (red || 1)
end
end
end
end
end