File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -55,31 +55,39 @@ def score_round_part2(line)
55
55
opp_choice , round_end = line . split ( " " )
56
56
opp_shape = OPPONENT_MAP . fetch ( opp_choice )
57
57
target_outcome = PART2_MAP . fetch ( round_end )
58
+
58
59
my_shape = case target_outcome
59
60
when :draw
60
61
opp_shape
61
62
when :win
62
- DEFEATED_BY . fetch ( opp_shape )
63
+ WHAT_DEFEATS . fetch ( opp_shape )
63
64
when :lose
64
- DEFEATS . fetch ( opp_shape )
65
+ WHAT_LOSES_TO . fetch ( opp_shape )
65
66
end
66
67
67
68
SHAPE_SCORES . fetch ( my_shape ) + OUTCOME_SCORES . fetch ( target_outcome )
68
69
end
69
70
70
71
def against ( opp_shape , my_shape )
71
72
return :draw if opp_shape == my_shape
72
- return :win if opp_shape == DEFEATS . fetch ( my_shape )
73
+ return :win if opp_shape == WHAT_LOSES_TO . fetch ( my_shape )
73
74
return :lose
74
75
end
75
76
76
- DEFEATS = {
77
+ # the name seems backwards here, but consider:
78
+ #
79
+ # WHAT_LOSES_TO.fetch(:rock) => :scissors
80
+ #
81
+ # or "What is defeated by rock?" -> "scissors"
82
+ WHAT_LOSES_TO = {
77
83
rock : :scissors ,
78
84
scissors : :paper ,
79
85
paper : :rock ,
80
86
}
81
87
82
- DEFEATED_BY = DEFEATS . invert
88
+ # ... and then we invert it so we can look up the
89
+ # other direction
90
+ WHAT_DEFEATS = WHAT_LOSES_TO . invert
83
91
84
92
OPPONENT_MAP = {
85
93
'A' => :rock ,
You can’t perform that action at this time.
0 commit comments