Forum: Ruby Deaf Calculus

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Luke K. (Guest)
on 2009-06-04 21:57
Attachment: Calculus.rb (0 Bytes)
Hey, I am trying a variation of Deaf Grandma program that takes off of
Tintin's Character Professor Calculus. I tried to make it... But it did
not work very well. Any help/advice?
Luke K. (Guest)
on 2009-06-04 22:08
Attachment: Calculus.rb (0 Bytes)
Luke K. wrote:
Okay, I just figured one thing out:
Instead of putting .capitalize, you put .upcase
What I would like to know is how to put in a random sentence, like you
make 7 different sentences, how could you make the program put a
sentence at random instead of a date?
Todd B. (Guest)
on 2009-06-05 00:41
(Received via mailing list)
On Thu, Jun 4, 2009 at 1:08 PM, Luke K. <removed_email_address@domain.invalid> 
wrote:
> Luke K. wrote:
> Okay, I just figured one thing out:
> Instead of putting .capitalize, you put .upcase
> What I would like to know is how to put in a random sentence, like you
> make 7 different sentences, how could you make the program put a
> sentence at random instead of a date?

Just a hint.

'daygs' used for "Snatch" reference :)...

array = ["Ya like daygs?", "Do I like daygs?", "Yeah, d'ya like
daygs", "Oh, 'do I like dahgs.'", "Yeah, I like dahgs."]
puts array[rand(array.size - 1)]

Todd
Brian C. (Guest)
on 2009-06-05 00:56
Todd B. wrote:
> array = ["Ya like daygs?", "Do I like daygs?", "Yeah, d'ya like
> daygs", "Oh, 'do I like dahgs.'", "Yeah, I like dahgs."]
> puts array[rand(array.size - 1)]

I think you want puts array[rand(array.size)], otherwise the last
element won't ever be used.

------------------------------------------------------------ Kernel#rand
     rand(max=0)    => number
------------------------------------------------------------------------
     Converts _max_ to an integer using max1 = max+.to_i.abs+. If the
     result is zero, returns a pseudorandom floating point number
     greater than or equal to 0.0 and less than 1.0. Otherwise, returns
     a pseudorandom integer greater than or equal to zero and less than
     max1.
Todd B. (Guest)
on 2009-06-05 03:15
(Received via mailing list)
On Thu, Jun 4, 2009 at 3:56 PM, Brian C. <removed_email_address@domain.invalid>
wrote:
> Todd B. wrote:
>> array = ["Ya like daygs?", "Do I like daygs?", "Yeah, d'ya like
>> daygs", "Oh, 'do I like dahgs.'", "Yeah, I like dahgs."]
>> puts array[rand(array.size - 1)]
>
> I think you want puts array[rand(array.size)], otherwise the last
> element won't ever be used.

Yes, yes; must read the docs before responding :-)
This topic is locked and can not be replied to.