ooops, sent it directly to Graham and not to this list. Cheers.

On 6/15/06, Mark Sargent <[EMAIL PROTECTED] > wrote:
On 6/15/06, Graham Smith <[EMAIL PROTECTED]> wrote:
Here are my solutions to the exercises

#!/usr/bin/ruby
a=[]
20.times { x = rand(100) + 1; a << x }
puts a.select { |v| v if v % 2 == 1 }

nice

> - Read all lines from standard input, then print them out in a random
> order. (Hint: Array#sort_by)  (Extra hint: There's more to the IO class
> than each_line -- there are also methods to read lines)

#!/usr/bin/ruby
a=STDIN.readlines.sort_by {rand}
puts a

any reason why you chose STDIN over gets

Cheers.

Mark Sargent.

_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders

Reply via email to