Last active
January 23, 2025 09:35
-
-
Save kissu/96301403de4085bccfd40848b7999284 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def acronym(sentence) | |
# we split the sentence into words | |
# grab first letter of each word | |
# join the first letters | |
final = [] | |
array_of_words = sentence.split(' ') | |
array_of_words.each do |word| | |
final << word[0].upcase | |
# p final | |
end | |
return final.join("") | |
end | |
puts acronym("Don't repeat yourself") == "DRY" | |
puts acronym("") == "" | |
puts acronym("working from home") == "WFH" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def acronym(sentence) | |
array_of_words = sentence.split(' ') | |
final = array_of_words.map do |word| | |
word[0].upcase | |
end | |
# p array_of_words | |
final.join("") | |
end | |
puts acronym("Don't repeat yourself") == "DRY" | |
puts acronym("") == "" | |
puts acronym("working from home") == "WFH" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rock_paper_scissors | |
choices = %w(rock paper scissors) | |
computer_choice = choices.sample | |
puts "{•̃_•̃}: #{computer_choice}" | |
print "(。◕‿‿◕。): " | |
player_choice = gets.chomp | |
return "You had one job...." unless choices.include?(player_choice) | |
if computer_choice == player_choice | |
return "========== DRAW =========" | |
elsif choices[choices.find_index(computer_choice) - 1] == player_choice | |
return "AI is taking your job soon... 😒" | |
else | |
return "Sarah Connor is still kicking HARD! 🤘🏻😎" | |
end | |
end | |
puts rock_paper_scissors() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HANDS = %w(rock paper scissors) | |
# The computer picks a hand | |
computer_hand = HANDS.sample | |
# The user picks a hand | |
player_hand = nil | |
loop do | |
puts "Please choose your hand (#{HANDS.join(", ")})" | |
print "> " | |
player_hand = gets.chomp | |
if HANDS.include?(player_hand) | |
break | |
else | |
puts "Wrong choice..." | |
end | |
end | |
if computer_hand == player_hand | |
puts "You both chose #{computer_hand}, draw." | |
else | |
if computer_hand == 'rock' | |
player_wins = player_hand == 'paper' | |
elsif computer_hand == 'paper' | |
player_wins = player_hand == 'scissors' | |
elsif computer_hand == 'scissors' | |
player_wins = player_hand == 'rock' | |
end | |
if player_wins | |
puts "The computer chose #{computer_hand}, you win!" | |
else | |
puts "The computer chose #{computer_hand}, computer wins!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment