You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
770 B
39 lines
770 B
8 years ago
|
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
|