Jump to content

Rock-paper-scissors: Difference between revisions

Added a Red answer
(Added 11l)
(Added a Red answer)
Line 4,820:
rascal>RPS("Rock")
str: "Computer played Paper. Paper wins!"</lang>
 
=={{header|Red}}==
<lang Rebol>
Red [Purpose: "Implement a rock-paper-scissors game with weighted probability"]
 
prior: ["r" "p" "s"]
win: ["p" "s" "r"]
 
forever [
print "choose rock: r, paper: p, or scissors: s"
pchoice: ask ""
unless any [pchoice = "r" pchoice = "p" pchoice = "s"] [break]
cchoice: random/only prior
pindex: index? find prior pchoice
cindex: index? find win cchoice
case [
pchoice = cchoice [print "tie"]
pindex = cindex [print "you lose"]
true [print "you win"]
]
append prior win/:pindex ;adds what would have beaten player
]
</lang>
 
=={{header|REXX}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.