tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View 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!";
}

View 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!"