Can't decide what to watch on TV? How about settling the dispute with a good old fashioned round of Paper Scissors Lizard Spock ? Given your opponents choice and a strategy ("win", "lose", or "tie"), return a string representing the choice(s) that would yield that desired outcome.
Ex:
rpsls("rock","lose")
ans = {"Spock", "paper"} %%you will lose if you choose either Spock or paper
rpsls("paper", "tie")
ans = "paper" %%you will tie if you select the same choice
Solution Stats
Problem Comments
6 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers22
Suggested Problems
-
How long is the longest prime diagonal?
410 Solvers
-
Calculate the height of an object dropped from the sky
284 Solvers
-
Sum the elements in either diagonal of a square matrix
221 Solvers
-
Given a matrix, swap the 2nd & 3rd columns
1264 Solvers
-
2246 Solvers
More from this Author1
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Is there any reason the order of the solution should matter (e.g., {'rock','paper'} vs {'paper','rock'})?
I had the same question as Tim and struggled to find a pattern. I never did find one.
Yeah sorry there was no pattern or order, I kind of just threw it together. I'll fix the test suite to accept any valid combination
Should be fixed now to accept any order of two elements. Thanks for the feedback!
Thank you. :-)
Thanks Hope. There's also the issue that I've been muttering "Rock, Paper, Scissors, Lizard, Spock" as an earworm since solving this problem, but I suppose there's nothing you can do to fix that.