Spreadsheet.Institute/

Home of Spreadsheet Lisp (SL)


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

        
            
    DEFINE(
        ROCKPAPERSCISSORS,
        LAMBDA(
            throw,
            LET(
                human,
                    CAPITALIZE(throw),
                robot,
                    PICKFROM(
                        "Rock",
                        "Paper",
                        "Scissors"),
                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 cuts 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 cuts 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