tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
20
Task/Rock-paper-scissors/Rascal/rock-paper-scissors-1.rascal
Normal file
20
Task/Rock-paper-scissors/Rascal/rock-paper-scissors-1.rascal
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import Prelude;
|
||||
|
||||
rel[str, str] whatbeats = {<"Rock", "Scissors">, <"Scissors", "Paper">, <"Paper", "Rock">};
|
||||
|
||||
list[str] ComputerChoices = ["Rock", "Paper", "Scissors"];
|
||||
|
||||
str CheckWinner(a, b){
|
||||
if(b == getOneFrom(whatbeats[a]))
|
||||
return a;
|
||||
elseif(a == getOneFrom(whatbeats[b]))
|
||||
return b;
|
||||
else return "Nobody";
|
||||
}
|
||||
|
||||
public str RPS(human){
|
||||
computer = getOneFrom(ComputerChoices);
|
||||
x = if(human == "Rock") "Paper"; elseif(human == "Paper") "Scissors"; else "Rock";
|
||||
ComputerChoices += x;
|
||||
return "Computer played <computer>. <CheckWinner(human, computer)> wins!";
|
||||
}
|
||||
29
Task/Rock-paper-scissors/Rascal/rock-paper-scissors-2.rascal
Normal file
29
Task/Rock-paper-scissors/Rascal/rock-paper-scissors-2.rascal
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
rascal>RPS("Rock")
|
||||
str: "Computer played Rock. Nobody wins!"
|
||||
|
||||
rascal>RPS("Rock")
|
||||
str: "Computer played Rock. Nobody wins!"
|
||||
|
||||
rascal>RPS("Rock")
|
||||
str: "Computer played Scissors. Rock wins!"
|
||||
|
||||
rascal>RPS("Rock")
|
||||
str: "Computer played Paper. Paper wins!"
|
||||
|
||||
rascal>RPS("Rock")
|
||||
str: "Computer played Paper. Paper wins!"
|
||||
|
||||
rascal>RPS("Rock")
|
||||
str: "Computer played Paper. Paper wins!"
|
||||
|
||||
rascal>RPS("Rock")
|
||||
str: "Computer played Paper. Paper wins!"
|
||||
|
||||
rascal>RPS("Rock")
|
||||
str: "Computer played Rock. Nobody wins!"
|
||||
|
||||
rascal>RPS("Rock")
|
||||
str: "Computer played Paper. Paper wins!"
|
||||
|
||||
rascal>RPS("Rock")
|
||||
str: "Computer played Paper. Paper wins!"
|
||||
Loading…
Add table
Add a link
Reference in a new issue