나는 이렇게 학습한다/Algorithm & SQL

0914. Rock Paper Scissors!

daco2020 2022. 9. 14. 22:36
반응형

Rock Paper Scissors

Let's play! You have to return which player won! In case of a draw return Draw!.

Examples(Input1, Input2 --> Output):

"scissors", "paper" --> "Player 1 won!"
"scissors", "rock" --> "Player 2 won!"
"paper", "paper" --> "Draw!"

image



Solution:

from typing import Dict


def check_draw(func):
    def wrapper(p1, p2):
        table = {"s":"p","r":"s","p":"r"}
        return p1 == p2 and "Draw!" or func(p1, p2, table)
    return wrapper        

@check_draw
def rps(p1: str, p2: str, table: Dict[str, str]):
    return table[p1[0]] == p2[0] and "Player 1 won!" or "Player 2 won!"


반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

0916. Do you speak "English"?  (0) 2022.09.16
0915. Beginner - Reduce but Grow  (0) 2022.09.15
0913. Take the Derivative  (0) 2022.09.13
알고리즘 포스팅 관련 공지  (0) 2022.09.13
0912. Fake Binary  (0) 2022.09.13