-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2.rb
More file actions
48 lines (41 loc) · 875 Bytes
/
day2.rb
File metadata and controls
48 lines (41 loc) · 875 Bytes
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
45
46
47
48
class Rpc
def initialize(input)
@total_score
input_file(input)
end
attr_reader :total_score
def input_file(input)
@total_score = 0
File.foreach(input) do |line|
@total_score += self.score_line(line)
end
end
def score_line(line)
shape = score_shape(line)
outcome = score_outcome(line)
return shape + outcome
end
def score_shape(line)
case line[2]
when 'X'
1
when 'Y'
2
when 'Z'
3
end
end
def score_outcome(line)
composite = line[0] + line[2]
case composite
when 'BX', 'CY', 'AZ'
0
when 'AX', 'BY', 'CZ'
3
when 'AY', 'BZ', 'CX'
6
end
end
end
today = Rpc.new("strat")
puts today.total_score