-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.rb
44 lines (38 loc) · 1.06 KB
/
card.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 Day04
##
# Class for representing a card
class Card
##
# @return [Integer] id of the card
attr_reader :id
##
# @return [Array<Integer>] array of owned numbers
attr_reader :owned
##
# @return [Array<Integer>] array of winning numbers
attr_reader :winning
##
# @param id [Integer] id of the card
# @param owned [Array<Integer>] array of owned numbers
# @param winning [Array<Integer>] array of winning numbers
def initialize(id:, owned:, winning:)
@id = id
@owned = owned
@winning = winning
end
##
# Get the matches of the card.
# That is, the numbers that are both owned and winning.
#
# @return [Array<Integer>] array of matches
def matches
return @matches unless @matches.nil?
@matches = winning.intersection(owned)
end
end
end
end
end