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.
8c813b41a057303ebd4e13196e301f58?d=identicon&s=25 Luke Kyrchner (lynxinator)
on 2009-06-04 19:57
Attachment: Calculus.rb (239 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?
8c813b41a057303ebd4e13196e301f58?d=identicon&s=25 Luke Kyrchner (lynxinator)
on 2009-06-04 20:08
Attachment: Calculus.rb (269 Bytes)
Luke Kyrchner 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?
289cf19aa581c445915c072bf45c5e25?d=identicon&s=25 Todd Benson (Guest)
on 2009-06-04 22:41
(Received via mailing list)
On Thu, Jun 4, 2009 at 1:08 PM, Luke Kyrchner <lynx557@gmail.com> wrote:
> Luke Kyrchner 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
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2009-06-04 22:56
Todd Benson 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.
289cf19aa581c445915c072bf45c5e25?d=identicon&s=25 Todd Benson (Guest)
on 2009-06-05 01:15
(Received via mailing list)
On Thu, Jun 4, 2009 at 3:56 PM, Brian Candler <b.candler@pobox.com>
wrote:
> Todd Benson 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.