Skip to content

Instantly share code, notes, and snippets.

@Acesmndr
Created May 18, 2024 20:42
Show Gist options
  • Save Acesmndr/5ef261c8f76e0bf0d1ceb856414e3709 to your computer and use it in GitHub Desktop.
Save Acesmndr/5ef261c8f76e0bf0d1ceb856414e3709 to your computer and use it in GitHub Desktop.
Test
def wins_rock_scissors_paper(player: str, opponent: str) -> bool:
# Normalize the casing of the input strings
player = player.lower()
opponent = opponent.lower()
# Define the winning conditions
winning_conditions = {
"rock": "scissors",
"paper": "rock",
"scissors": "paper"
}
# Check if the player's throw beats the opponent's throw
return winning_conditions.get(player) == opponent
# Example usage:
print(wins_rock_scissors_paper("rock", "scissors")) # True
print(wins_rock_scissors_paper("paper", "rock")) # True
print(wins_rock_scissors_paper("scissors", "paper")) # True
print(wins_rock_scissors_paper("rock", "rock")) # False
print(wins_rock_scissors_paper("rock", "paper")) # False
def wins_rock_scissors_paper(player: str, opponent: str) -> bool:
# Define the winning conditions with all possible casing variations
winning_conditions = {
"rock": ["scissors", "SCISSORS", "Scissors"],
"ROCK": ["scissors", "SCISSORS", "Scissors"],
"Rock": ["scissors", "SCISSORS", "Scissors"],
"ROck": ["scissors", "SCISSORS", "Scissors"],
"rocK": ["scissors", "SCISSORS", "Scissors"],
"roCK": ["scissors", "SCISSORS", "Scissors"],
"rOCK": ["scissors", "SCISSORS", "Scissors"],
"rock": ["Scissors", "SCISSORS", "scissors"],
"paper": ["rock", "ROCK", "Rock"],
"PAPER": ["rock", "ROCK", "Rock"],
"Paper": ["rock", "ROCK", "Rock"],
"PAper": ["rock", "ROCK", "Rock"],
"paPER": ["rock", "ROCK", "Rock"],
"paper": ["Rock", "ROCK", "rock"],
"scissors": ["paper", "PAPER", "Paper"],
"SCISSORS": ["paper", "PAPER", "Paper"],
"Scissors": ["paper", "PAPER", "Paper"],
"sCISSORS": ["paper", "PAPER", "Paper"],
"scISSORS": ["paper", "PAPER", "Paper"],
"sciSSORS": ["paper", "PAPER", "Paper"],
"scisSORS": ["paper", "PAPER", "Paper"],
"scissORS": ["paper", "PAPER", "Paper"],
"scissoRS": ["paper", "PAPER", "Paper"],
"scissorS": ["paper", "PAPER", "Paper"],
"scissors": ["Paper", "PAPER", "paper"],
}
# Check if the player's throw beats the opponent's throw
return opponent in winning_conditions.get(player, [])
# Example usage:
print(wins_rock_scissors_paper("rock", "scissors")) # True
print(wins_rock_scissors_paper("paper", "rock")) # True
print(wins_rock_scissors_paper("scissors", "paper")) # True
print(wins_rock_scissors_paper("rock", "rock")) # False
print(wins_rock_scissors_paper("rock", "paper")) # False
def custom_lower(s: str) -> str:
# Map of uppercase letters to their lowercase counterparts
lower_map = {
'A': 'a', 'B': 'b', 'C': 'c', 'D': 'd', 'E': 'e',
'F': 'f', 'G': 'g', 'H': 'h', 'I': 'i', 'J': 'j',
'K': 'k', 'L': 'l', 'M': 'm', 'N': 'n', 'O': 'o',
'P': 'p', 'Q': 'q', 'R': 'r', 'S': 's', 'T': 't',
'U': 'u', 'V': 'v', 'W': 'w', 'X': 'x', 'Y': 'y',
'Z': 'z'
}
# Convert the string to lowercase using the map
return ''.join(lower_map.get(c, c) for c in s)
def wins_rock_scissors_paper(player: str, opponent: str) -> bool:
# Normalize the casing of the input strings using custom_lower
player = custom_lower(player)
opponent = custom_lower(opponent)
# Define the winning conditions
winning_conditions = {
"rock": "scissors",
"paper": "rock",
"scissors": "paper"
}
# Check if the player's throw beats the opponent's throw
return winning_conditions.get(player) == opponent
# Example usage:
print(wins_rock_scissors_paper("rock", "scissors")) # True
print(wins_rock_scissors_paper("paper", "rock")) # True
print(wins_rock_scissors_paper("scissors", "paper")) # True
print(wins_rock_scissors_paper("rock", "rock")) # False
print(wins_rock_scissors_paper("rock", "paper")) # False
print(wins_rock_scissors_paper("ROCK", "SCISSORS")) # True
print(wins_rock_scissors_paper("PAPER", "ROCK")) # True
print(wins_rock_scissors_paper("SCISSORS", "PAPER")) # True
function customLower(s) {
// Map of uppercase letters to their lowercase counterparts
const lowerMap = {
'A': 'a', 'B': 'b', 'C': 'c', 'D': 'd', 'E': 'e',
'F': 'f', 'G': 'g', 'H': 'h', 'I': 'i', 'J': 'j',
'K': 'k', 'L': 'l', 'M': 'm', 'N': 'n', 'O': 'o',
'P': 'p', 'Q': 'q', 'R': 'r', 'S': 's', 'T': 't',
'U': 'u', 'V': 'v', 'W': 'w', 'X': 'x', 'Y': 'y',
'Z': 'z'
};
// Convert the string to lowercase using the map
let lowerString = '';
for (let i = 0; i < s.length; i++) {
const char = s[i];
lowerString += lowerMap[char] || char;
}
return lowerString;
}
function wins_rock_scissors_paper(player, opponent) {
// Normalize the casing of the input strings using customLower
player = customLower(player);
opponent = customLower(opponent);
// Define the winning conditions
const winningConditions = {
"rock": "scissors",
"paper": "rock",
"scissors": "paper"
};
// Check if the player's throw beats the opponent's throw
return winningConditions[player] === opponent;
}
// Example usage:
console.log(wins_rock_scissors_paper("rock", "scissors")); // true
console.log(wins_rock_scissors_paper("paper", "rock")); // true
console.log(wins_rock_scissors_paper("scissors", "paper")); // true
console.log(wins_rock_scissors_paper("rock", "rock")); // false
console.log(wins_rock_scissors_paper("rock", "paper")); // false
console.log(wins_rock_scissors_paper("ROCK", "SCISSORS")); // true
console.log(wins_rock_scissors_paper("PAPER", "ROCK")); // true
console.log(wins_rock_scissors_paper("SCISSORS", "PAPER")); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment