39 lines
770 B
Ruby
39 lines
770 B
Ruby
def main
|
|
loop do
|
|
secret_number = rand(0..99)
|
|
hint_0 = secret_number - rand(0..49)
|
|
|
|
loop do
|
|
say "#{secret_number - hint_0} + #{hint_0} is", newline: false
|
|
print '?: '
|
|
begin
|
|
answer = Integer($stdin.readline.strip)
|
|
if answer == secret_number
|
|
say 'You got it!'
|
|
break
|
|
else
|
|
say 'That is so incorrect!'
|
|
end
|
|
rescue => e
|
|
$stderr.puts e
|
|
say 'NO, Human!'
|
|
end
|
|
end
|
|
|
|
say 'Do you want to play again? ', newline: false
|
|
print '[Y/n] '
|
|
if $stdin.readline.strip.downcase =~ /^n/
|
|
say 'Goodbye, Human!'
|
|
break
|
|
end
|
|
end
|
|
end
|
|
|
|
def say(msg, newline: true)
|
|
print msg
|
|
print "\n" if newline
|
|
system "say -v ralph #{msg.inspect}"
|
|
end
|
|
|
|
main
|