Skip to content

Instantly share code, notes, and snippets.

@johncrisostomo
Created May 9, 2011 19:02
Show Gist options
  • Save johncrisostomo/963145 to your computer and use it in GitHub Desktop.
Save johncrisostomo/963145 to your computer and use it in GitHub Desktop.
Deaf Grandma
#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
#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