|
|
@ -6,10 +6,19 @@ solve(InputData) -> |
|
|
RoundData = binary:split(InputData, <<$\n>>, [trim_all, global]), |
|
|
RoundData = binary:split(InputData, <<$\n>>, [trim_all, global]), |
|
|
Rounds = lists:map(fun parse_round/1, RoundData), |
|
|
Rounds = lists:map(fun parse_round/1, RoundData), |
|
|
RoundPoints = lists:map(fun score_round/1, Rounds), |
|
|
RoundPoints = lists:map(fun score_round/1, Rounds), |
|
|
{lists:sum(RoundPoints), none}. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rounds2 = lists:map(fun parse_round2/1, RoundData), |
|
|
|
|
|
RoundPoints2 = lists:map(fun score_round/1, Rounds2), |
|
|
|
|
|
{lists:sum(RoundPoints), lists:sum(RoundPoints2)}. |
|
|
|
|
|
|
|
|
parse_round(<<TheirCode, $\s, YourCode>>) -> {parse_theirs(TheirCode), parse_yours(YourCode)}. |
|
|
parse_round(<<TheirCode, $\s, YourCode>>) -> {parse_theirs(TheirCode), parse_yours(YourCode)}. |
|
|
|
|
|
|
|
|
|
|
|
parse_round2(<<TheirCode, $\s, OutcomeCode>>) -> |
|
|
|
|
|
OutcomeScore = parse_outcome_points(OutcomeCode), |
|
|
|
|
|
TheirShape = parse_theirs(TheirCode), |
|
|
|
|
|
[YourShape] = [Shape || Shape <- [rock, paper, scissors], round_points({TheirShape, Shape}) == OutcomeScore], |
|
|
|
|
|
{TheirShape, YourShape}. |
|
|
|
|
|
|
|
|
score_round(Round = {_Theirs, Yours}) -> round_points(Round) + shape_points(Yours). |
|
|
score_round(Round = {_Theirs, Yours}) -> round_points(Round) + shape_points(Yours). |
|
|
|
|
|
|
|
|
parse_theirs($A) -> rock; |
|
|
parse_theirs($A) -> rock; |
|
|
@ -20,6 +29,10 @@ parse_yours($X) -> rock; |
|
|
parse_yours($Y) -> paper; |
|
|
parse_yours($Y) -> paper; |
|
|
parse_yours($Z) -> scissors. |
|
|
parse_yours($Z) -> scissors. |
|
|
|
|
|
|
|
|
|
|
|
parse_outcome_points($X) -> 0; |
|
|
|
|
|
parse_outcome_points($Y) -> 3; |
|
|
|
|
|
parse_outcome_points($Z) -> 6. |
|
|
|
|
|
|
|
|
round_points({rock, paper}) -> 6; |
|
|
round_points({rock, paper}) -> 6; |
|
|
round_points({paper, scissors}) -> 6; |
|
|
round_points({paper, scissors}) -> 6; |
|
|
round_points({scissors, rock}) -> 6; |
|
|
round_points({scissors, rock}) -> 6; |
|
|
|