S.I/Lisp/

ROCKPAPERSCISSORS




=ROCKPAPERSCISSORS("Paper")
-> "You win! Paper covers Rock."

=ROCKPAPERSCISSORS("Paper")
-> "You lose! Scissors cut Paper."
        



DEFINE(
    ROCKPAPERSCISSORS,
    LAMBDA(
        throw,
        LET(
            human,
                CAPITALIZE(LOWER(DEFAULT(throw, ""))),
            robot,
                PICK(
                    "Rock",
                    "Paper",
                    "Scissors"),
            CONCAT(
                FORMAT(
                    "You threw {1}. SL threw {2}. ",
                    human,
                    robot),
                IFS(
                    CASE(
                        human,
                            robot),
                        FORMAT(
                            "It's a tie! {1} vs. {1}",
                            human),
                    CASE(
                        human,
                            "Paper",
                        robot,
                            "Rock"),
                        "You win! Paper covers Rock.",
                    CASE(
                        human,
                            "Paper",
                        robot,
                            "Scissors"),
                        "You lose! Scissors cut Paper.",
                    CASE(
                        human,
                            "Rock",
                        robot,
                            "Scissors"),
                        "You win! Rock crushes Scissors.",
                    CASE(
                        human,
                            "Rock",
                        robot,
                            "Paper"),
                        "You lose! Paper covers Rock.",
                    CASE(
                        human,
                            "Scissors",
                        robot,
                            "Paper"),
                        "You win! Scissors cut Paper.",
                    CASE(
                        human,
                            "Scissors",
                        robot,
                            "Rock"),
                        "You lose! Rock crushes Scissors.",
                    OTHERWISE,
                        "Invalid throw. Please choose Rock, Paper, or Scissors.")))))
        
        



Help us optimize this function