Skip to content

Instantly share code, notes, and snippets.

@teh
Created March 22, 2012 20:07
Show Gist options
  • Save teh/2163031 to your computer and use it in GitHub Desktop.
Save teh/2163031 to your computer and use it in GitHub Desktop.
def from_number(r)
third = 1.0 / 3
if r>= 0 and r<= third then choice = "r" end
if r >=third and r<= 2*third then choice = 'p' end
if r>= 2*third and r<= 1 then choice ='s' end
return choice
end
def play(weapon)
opponent = from_number(rand)
if weapon == opponent then result ="d"
else
wins = "pr", "rs", "sp"
choice = weapon + opponent
if wins.count(choice) == 0 then result = "l" end
if wins.count(choice) == 1 then result = "w" end
end
return result, opponent
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment