Created
May 9, 2011 19:02
-
-
Save johncrisostomo/963145 to your computer and use it in GitHub Desktop.
Deaf Grandma
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
#only quits after three successive BYEs | |
def random_year | |
rand(21) + 1930 | |
end | |
count = 0 | |
while count <= 2 | |
print 'Say something to grandma : ' | |
input = gets.chomp | |
count += 1 if input == 'BYE' | |
count = 0 if input != 'BYE' | |
unless input == input.upcase | |
puts 'Grandma responds: HUH?! SPEAK UP, SONNY!' | |
else | |
puts "Grandma responds: NO, NOT SINCE #{random_year}!" | |
end | |
end |
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
#only quits after three successive BYEs | |
def random_year | |
rand(21) + 1930 | |
end | |
bye_count = Hash.new(0) | |
while input = gets.chomp | |
break if bye_count["BYE"] == 2 | |
bye_count["BYE"] += 1 if input == 'BYE' | |
bye_count["BYE"] -= 1 if input != 'BYE' && bye_count["BYE"] > 0 | |
unless input == input.upcase | |
puts 'Grandma responds: HUH?! SPEAK UP, SONNY!' | |
else | |
puts "Grandma responds: NO, NOT SINCE #{random_year}!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment